예제 #1
0
def is_synced():
    aw = config.app_window
    if aw.qmc.roastUUID is None:
        return not bool(aw.curFile)
    else:
        res = sync.getSync(aw.qmc.roastUUID)
        return bool(res)
예제 #2
0
파일: queue.py 프로젝트: scooter9/artisan
 def addSyncItem(self, item):
     # successfully transmitted, we add/update the roasts UUID sync-cache
     if "roast_id" in item["data"] and "modified_at" in item["data"]:
         # we update the plus status icon if the given roast_id was not yet in the sync cache and thus new
         if sync.getSync(item["data"]["roast_id"]) is None:
             sync.addSync(item["data"]["roast_id"],
                          util.ISO86012epoch(item["data"]["modified_at"]))
             config.app_window.updatePlusStatusSignal.emit(
             )  # @UndefinedVariable
         else:
             sync.addSync(item["data"]["roast_id"],
                          util.ISO86012epoch(item["data"]["modified_at"]))
예제 #3
0
 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: looking for next item to be fetched")
         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
         keepTask = False
         while iters > 0:
             config.logger.debug("queue: -> remaining iterations: %s",
                                 iters)
             r = None
             try:
                 r = connection.sendData(item["url"], item["data"],
                                         item["verb"])
                 r.raise_for_status()
                 iters = 0
                 # successfully transmitted, we add/update the roasts UUID sync-cache
                 if "roast_id" in item["data"] and "modified_at" in item[
                         "data"]:
                     # we update the plus status icon if the given roast_id was not yet in the sync cache and thus new
                     if sync.getSync(item["data"]["roast_id"]) is None:
                         sync.addSync(
                             item["data"]["roast_id"],
                             util.ISO86012epoch(
                                 item["data"]["modified_at"]))
                         config.app_window.updatePlusStatusSignal.emit(
                         )  # @UndefinedVariable
                     else:
                         sync.addSync(
                             item["data"]["roast_id"],
                             util.ISO86012epoch(
                                 item["data"]["modified_at"]))
             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)
                 if r is not None and r.status_code == 401:  # authentication failed
                     controller.disconnect(remove_credentials=False)
                     iters = 0  # we don't retry and keep the task item
                     keepTask = True
                 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 or others
                     # something went wrong we don't mark this task as done and retry
                     iters = iters - 1
                     time.sleep(config.queue_retry_delay)
         if not keepTask:
             # 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)
예제 #4
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