def tasks_livetrack(): params = task_util.get_payload(flask.request) url = params['url'] publish = params['publish'] logging.info(f'process/livetrack: {url} {publish}') try: sync_helper.do(TrackWorker(url=url, publish=publish), work_key=url) except SyncException: return responses.OK_SYNC_EXCEPTION return responses.OK
def tasks_xsync_tasks_backfill(): params = task_util.get_payload(flask.request) source_key = params['source_key'] dest_key = params['dest_key'] start = params['start'] end = params['end'] logging.info('xsync_tasks_backfill: %s->%s', source_key, dest_key) try: sync_helper.do(BackfillWorker(source_key, dest_key, start, end), work_key=source_key) except SyncException: return responses.OK_SYNC_EXCEPTION return responses.OK
def tasks_rides(): payload = task_util.get_payload(flask.request) service = Service.get('google', Bot.key()) data = payload['data'] logging.info('tasks_rides: %s', data.get('historyId')) try: client = create_gmail_client(service) sync_helper.do( PubsubWorker(service, data, client), work_key='%s/%s' % (service.key.parent.name, data['historyId']), ) except SyncException: return responses.OK_SYNC_EXCEPTION return responses.OK
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
def withings_tasks_weight_trend_task(): params = task_util.get_payload(flask.request) event = params['event'] logging.info('WeightTrendEvent: %s', event.key) service_key = event.key.parent service = ds_util.client.get(service_key) if service is None: logging.error('WeightTrendEvent: No service: %s', event.key) return responses.OK_NO_SERVICE try: if service.key.name == 'withings': sync_helper.do(WeightTrendWorker(service, event), work_key=event.key) except SyncException: return responses.OK_SYNC_EXCEPTION return responses.OK
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
def process_event_task(): params = task_util.get_payload(flask.request) event = params['event'] logging.info('Event: %s', event.key) # First try to get the service using the event.key's service. # If this event is coming from an old subscription / secret url, which # embeds a service_key in it, then we might get these. service_key = event.key.parent service = ds_util.client.get(service_key) if service is None: logging.error('Event: No service: %s', event.key) return responses.OK_NO_SERVICE if not Service.has_credentials(service): logging.warning('Event: No credentials: %s', event.key) return responses.OK_NO_CREDENTIALS try: sync_helper.do(EventsWorker(service, event), work_key=event.key) except SyncException: return responses.OK_SYNC_EXCEPTION return responses.OK
def sync_club(club_id): logging.debug('Syncing: %s', club_id) service = Service.get('strava', parent=Bot.key()) sync_helper.do(ClubWorker(club_id, service), work_key=service.key) return responses.OK