コード例 #1
0
def getUpdate(uuid, file=None):
    config.logger.info("sync:getUpdate(" + str(uuid) + "," + str(file) + ")")
    if uuid is not None:
        aw = config.app_window
        if aw.editgraphdialog is None and controller.is_connected():
            try:
                aw.editgraphdialog = False  # block opening the Roast Properties dialog while syncing from the server
                aw.updatePlusStatusSignal.emit()  # show syncing icon
                QTimer.singleShot(2, lambda: fetchServerUpdate(uuid, file))
            except Exception as e:
                config.logger.error("sync: Exception in getUpdate() %s", e)
コード例 #2
0
ファイル: queue.py プロジェクト: scooter9/artisan
 def run(self):
     global queue
     config.logger.debug("queue:run()")
     time.sleep(config.queue_start_delay)
     self.resume()  # unpause self
     item = None
     while True:
         time.sleep(config.queue_task_delay)
         with self.state:
             if self.paused:
                 self.state.wait()  # block until notified
         config.logger.debug("queue: -> qsize: %s", queue.qsize())
         config.logger.debug("queue: looking for next item to be fetched")
         try:
             if item is None:
                 item = queue.get()
             time.sleep(config.queue_task_delay)
             config.logger.debug("queue: -> worker processing item: %s",
                                 item)
             iters = config.queue_retries + 1
             while iters > 0:
                 config.logger.debug("queue: -> remaining iterations: %s",
                                     iters)
                 r = None
                 try:
                     # we upload only full roast records, or partial updates in case the are under sync (registered in the sync cache)
                     if is_full_roast_record(item["data"]) or (
                             "roast_id" in item["data"]
                             and sync.getSync(item["data"]["roast_id"])):
                         controller.connect(clear_on_failure=False,
                                            interactive=False)
                         r = connection.sendData(item["url"], item["data"],
                                                 item["verb"])
                         r.raise_for_status()
                         # successfully transmitted, we add/update the roasts UUID sync-cache
                         iters = 0
                         self.addSyncItem(item)
                     else:
                         # partial sync updates for roasts not registered for syncing are ignored
                         iters = 0
                 except ConnectionError as e:
                     try:
                         if controller.is_connected():
                             config.logger.debug(
                                 "queue: -> connection error, disconnecting: %s",
                                 e)
                             # we disconnect, but keep the queue running to let it automatically reconnect if possible
                             controller.disconnect(remove_credentials=False,
                                                   stop_queue=False)
                     except:
                         pass
                     # we don't change the iter, but retry to connect after a delay in the next iteration
                     time.sleep(config.queue_retry_delay)
                 except Exception as e:
                     config.logger.debug("queue: -> task failed: %s", e)
                     if r is not None:
                         config.logger.debug("queue: -> status code %s",
                                             r.status_code)
                     else:
                         config.logger.debug("queue: -> no status code")
                     if r is not None and r.status_code == 401:  # authentication failed
                         try:
                             if controller.is_connected():
                                 config.logger.debug(
                                     "queue: -> connection error, disconnecting: %s",
                                     e)
                                 # we disconnect, but keep the queue running to let it automatically reconnect if possible
                                 controller.disconnect(
                                     remove_credentials=False,
                                     stop_queue=False)
                         except:
                             pass
                         # we don't change the iter, but retry to connect after a delay in the next iteration
                         time.sleep(config.queue_retry_delay)
                     elif r is not None and r.status_code == 409:  # conflict
                         iters = 0  # we don't retry, but remove the task as it is faulty
                     else:  # 500 internal server error, 429 Client Error: Too Many Requests, 404 Client Error: Not Found or others
                         # something went wrong we don't mark this task as done and retry
                         iters = iters - 1
                         time.sleep(config.queue_retry_delay)
             # we call task_done to remove the item from the queue
             queue.task_done()
             item = None
             config.logger.debug("queue: -> task done")
             config.logger.debug("queue: end of run:while paused=%s",
                                 self.paused)
         except Exception as e:
             pass