Пример #1
0
    def run(self):
        while not UPDATE_DONE:

            QUEUE_LOCK.acquire()

            if not ACCOUNT_QUEUE.empty():
                (account_num, role_name, arns) = ACCOUNT_QUEUE.get()

                self.app.logger.info("Thread #{} updating account {} with {} arns".format(
                                     self.thread_ID, account_num, 'all' if arns[0] == 'all' else len(arns)))

                QUEUE_LOCK.release()

                account = AccountToUpdate(self.app, account_num, role_name, arns)
                ret_code, aa_data = account.update_account()

                if ret_code != 0:  # retrieve wasn't successful, put back on queue
                    QUEUE_LOCK.acquire()
                    ACCOUNT_QUEUE.put((account_num, role_name, arns))
                    QUEUE_LOCK.release()

                self.app.logger.info("Thread #{} persisting data for account {}".format(self.thread_ID, account_num))

                DB_LOCK.acquire()
                persist_aa_data(self.app, aa_data)
                DB_LOCK.release()

                self.app.logger.info("Thread #{} FINISHED persisting data for account {}".format(self.thread_ID, account_num))
            else:
                QUEUE_LOCK.release()
Пример #2
0
    def run(self):
        while not UPDATE_DONE:
            self.on_ready.send(self)

            QUEUE_LOCK.acquire()

            if not ACCOUNT_QUEUE.empty():
                (account_num, role_name, arns) = ACCOUNT_QUEUE.get()

                self.app.logger.info(
                    "Thread #{} updating account {} with {} arns".format(
                        self.thread_ID, account_num,
                        'all' if arns[0] == 'all' else len(arns)))

                self.app.logger.debug(
                    f"ACCOUNT_QUEUE depth now ~ {ACCOUNT_QUEUE.qsize()}")

                QUEUE_LOCK.release()

                try:
                    account = AccountToUpdate(self.app, account_num, role_name,
                                              arns)
                    ret_code, aa_data = account.update_account()
                except Exception as e:
                    self.on_failure.send(self, error=e)
                    self.app.logger.exception(
                        f"Thread #{self.thread_ID} caught exception - {e} - while attempting to update account {account_num}. Continuing."
                    )
                    # Assume that whatever went wrong isn't transient; to avoid an
                    # endless loop we don't put the account back on the queue.
                    continue

                if ret_code != 0:  # retrieve wasn't successful, put back on queue
                    self.on_failure.send(self)
                    QUEUE_LOCK.acquire()
                    ACCOUNT_QUEUE.put((account_num, role_name, arns))
                    QUEUE_LOCK.release()

                self.app.logger.info(
                    "Thread #{} persisting data for account {}".format(
                        self.thread_ID, account_num))

                DB_LOCK.acquire()
                persist_aa_data(self.app, aa_data)
                DB_LOCK.release()

                self.on_complete.send(self)
                self.app.logger.info(
                    "Thread #{} FINISHED persisting data for account {}".
                    format(self.thread_ID, account_num))
            else:
                QUEUE_LOCK.release()