Exemple #1
0
def addRoast(roast_record=None):
    global queue
    try:
        config.logger.info("queue:addRoast()")
        if roast_record == None:
            r = roast.getRoast()
        else:
            r = roast_record
        # if modification date is not set yet, we add the current time as modified_at timestamp as float EPOCH with millisecond
        if not "modified_at" in r:
            r["modified_at"] = util.epoch2ISO8601(time.time())
        config.logger.debug("queue: -> roast: %s", r)
        # check if all required data is available before queueing this up
        if "roast_id" in r and r["roast_id"] and \
           (roast_record is not None or ("date" in r and r["date"] and "amount" in r)): # amount can be 0 but has to be present
            # put in upload queue
            config.logger.debug("queue: -> put in queue")
            config.app_window.sendmessage(
                QApplication.translate(
                    "Plus", "Queuing roast for upload to artisan.plus",
                    None))  # @UndefinedVariable
            queue.put({"url": config.roast_url, "data": r, "verb": "POST"})
            config.logger.debug("queue: -> roast queued up")
            config.logger.debug("queue: -> qsize: %s", queue.qsize())
            sync.setSyncRecordHash(r)
        else:
            config.logger.debug(
                "queue: -> roast not queued as mandatory info missing")
    except Exception as e:
        import sys
        _, _, exc_tb = sys.exc_info()
        config.logger.error("queue: Exception in addRoast() in line %s: %s",
                            exc_tb.tb_lineno, e)
Exemple #2
0
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)
Exemple #3
0
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
Exemple #4
0
def sync():
    try:
        config.logger.info("sync:sync()")
        aw = config.app_window
        rr = roast.getRoast()
        _,computed_sync_record_hash = roast.getSyncRecord(rr)
        if aw.qmc.plus_sync_record_hash is None or aw.qmc.plus_sync_record_hash != computed_sync_record_hash:
            # the sync record of the loaded profile is not consistent or missing, offline changes (might) have been applied
            aw.qmc.fileDirty() # set file dirty flag
            clearSyncRecordHash() # clear sync record hash cash to trigger an upload of the modified plus sync record on next save
        else:
            setSyncRecordHash(h = computed_sync_record_hash) # we remember that consistent state to be able to detect future modifications
        getUpdate(aw.qmc.roastUUID,aw.curFile) # now we check for updates on the server side
    except Exception as e:
        import sys
        _, _, exc_tb = sys.exc_info()
        config.logger.error("sync: Exception in sync() line %s: %s",exc_tb.tb_lineno,e)