def tasks_event(): params = task_util.get_payload(flask.request) event = params['event'] logging.info('SlackEvent: %s', event.key) if event['event']['type'] == 'link_shared': return _process_link_shared(event) return responses.OK_SUB_EVENT_UNKNOWN
def _withings_trainerroad(request, user_key, measure): params = task_util.get_payload(request) user_key = params['user_key'] measure = params['measure'] logging.info('ProcessMeasure: withings_trainerroad: %s %s', user_key, measure) trainerroad_service = Service.get('trainerroad', parent=user_key) if not Service.has_credentials(trainerroad_service, required_key='password'): logging.debug('ProcessMeasure: Trainerroad not connected') return responses.OK if not measure.get('weight'): logging.debug('ProcessMeasure: Skipping non-weight measure.') return responses.OK try: client = trainerroad_create_client(trainerroad_service) with client: client.weight = measure['weight'] except Exception: logging.exception('ProcessMeasure: Failed: %s', measure) return responses.OK_SYNC_EXCEPTION return responses.OK
def xsync_tasks_measure(): params = task_util.get_payload(flask.request) user_key = params['user_key'] measure = params['measure'] logging.info('ProcessMeasure: %s %s', user_key, measure) _withings_garmin(flask.request, user_key, measure) _withings_trainerroad(flask.request, user_key, measure) return responses.OK
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 _withings_garmin(request, user_key, measure): params = task_util.get_payload(request) user_key = params['user_key'] measure = params['measure'] logging.info('ProcessMeasure: withings_garmin: %s %s', user_key, measure) garmin_service = Service.get('garmin', parent=user_key) if not Service.has_credentials(garmin_service, required_key='password'): logging.debug('ProcessMeasure: Garmin not connected') return responses.OK if not measure.get('weight'): logging.debug('ProcessMeasure: Skipping non-weight measure.') return responses.OK try: client = garmin_client.create(garmin_service) client.set_weight(measure['weight'], measure['date']) except Exception: logging.exception('ProcessMeasure: Failed: %s', measure) return responses.OK_SYNC_EXCEPTION return responses.OK
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 tasks_livetrack(): params = task_util.get_payload(flask.request) track = params['track'] logging.info('process/livetrack: %s', track) return _process_track(track)