Пример #1
0
    def do():
        for service in services:
            if service['sync_state'].get('syncing') and force:
                logging.debug('Forcing sync finished: %s', service.key)
                Service.set_sync_finished(service, error='Forced sync')

            if service['sync_state'].get('syncing'):
                logging.debug('Not enqueuing sync for %s; already started.',
                              service.key)
                continue
            Service.set_sync_enqueued(service)
            task = {
                'entity': _params_entity(service_key=service.key),
                'relative_uri':
                '/services/%s/tasks/sync' % (service.key.name, ),
                'service': 'backend',
            }
            _queue_task(**task)
            logging.debug('Added: %s', task)
Пример #2
0
def sync():
    logging.debug('Syncing: google')
    payload = task_util.get_payload(flask.request)

    service = ds_util.client.get(payload['service_key'])
    if not Service.has_credentials(service):
        Service.set_sync_finished(service, error='No credentials')
        return responses.OK_NO_CREDENTIALS

    try:
        Service.set_sync_started(service)
        client = create_gmail_client(service)
        sync_helper.do(Worker(service, client), work_key=service.key)
        Service.set_sync_finished(service)
        return responses.OK
    except SyncException as e:
        Service.set_sync_finished(service, error=str(e))
        return responses.OK_SYNC_EXCEPTION
Пример #3
0
def sync():
    logging.debug('Syncing: trainerroad')
    params = task_util.get_payload(flask.request)

    service = ds_util.client.get(params['service_key'])
    if not Service.has_credentials(service, required_key='password'):
        logging.warning('No creds: %s', service.key)
        Service.set_sync_finished(service, error='No credentials')
        return responses.OK_NO_CREDENTIALS

    try:
        Service.set_sync_started(service)
        sync_helper.do(Worker(service), work_key=service.key)
        Service.set_sync_finished(service)
        return responses.OK
    except SyncException as e:
        Service.set_sync_finished(service, error=str(e))
        return responses.OK_SYNC_EXCEPTION