def updateSyncRecordHashAndSync(): try: config.logger.info("controller:updateSyncRecordHashAndSync()") if is_on(): roast_record = roast.getRoast() sync_record, sync_record_hash = roast.getSyncRecord(roast_record) if is_synced(): # check if profile is under sync already server_updates_modified_at = sync.getApplidedServerUpdatesModifiedAt( ) if server_updates_modified_at is not None and "roast_id" in roast_record: sync.addSync(roast_record["roast_id"], server_updates_modified_at) sync.setApplidedServerUpdatesModifiedAt(None) # artisan.plus is ON and the profile is under sync if sync.syncRecordUpdated(roast_record): # we push updates on the sync record back to the server via the queue queue.addRoast(sync_record) elif "roast_id" in roast_record and queue.full_roast_in_queue( roast_record["roast_id"]): # in case this roast is not yet in sync cache as it has not been successfully uploaded, but a corresponding full roast # record is already in the uploading queue we add this updating sync_record also to the queue queue.addRoast(sync_record) return sync_record_hash else: return None except Exception as e: import sys _, _, exc_tb = sys.exc_info() config.logger.error( "controller: Exception in updateSyncRecordHashAndSync() line %s: %s", exc_tb.tb_lineno, e) return None
def updateSyncRecordHashAndSync(): try: config.logger.info("controller:updateSyncRecordHashAndSync()") if is_connected(): roast_record = roast.getRoast() sync_record, sync_record_hash = roast.getSyncRecord(roast_record) if is_synced(): server_updates_modified_at = sync.getApplidedServerUpdatesModifiedAt( ) if server_updates_modified_at is not None and "roast_id" in roast_record: sync.addSync(roast_record["roast_id"], server_updates_modified_at) sync.setApplidedServerUpdatesModifiedAt(None) # we are connected and the profile is under sync if sync.syncRecordUpdated(roast_record): # we push updates on the sync record back to the server queue.addRoast(sync_record) return sync_record_hash else: return None except Exception as e: import sys _, _, exc_tb = sys.exc_info() config.logger.error( "controller: Exception in updateSyncRecordHashAndSync() line %s: %s", exc_tb.tb_lineno, e)
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 sync.addSync(item["data"]["roast_id"], util.ISO86012epoch(item["data"]["modified_at"])) config.app_window.updatePlusStatusSignal.emit( ) # @UndefinedVariable
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"]))
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)