def init_handler(self, task, lock_key): logger.info(f"initializing task handler for: {task.name}/{task.key}") handler = TaskRun(task_id=task.id, lock_key=lock_key, state="PENDING") app.db.session.add(handler) app.db.session.commit() handler.set("PENDING") app.db.session.commit() return handler
def poll_self_task(self, *args, **kwargs): with TaskHandler.execute(bind=self) as handler: petition = Petition.query.get(kwargs["id"]) kwargs = handler.getcallkwargs(petition.poll_self, kwargs) record = petition.poll_self(**kwargs) logger.info(f"polled petition id: {petition.id}") return handler.commit(result=record, schema=RecordSchema())
def update_trend_indexes_task(self, *args, **kwargs): with TaskHandler.execute(bind=self) as handler: kwargs = handler.getcallkwargs(Petition.update_trend_indexes, kwargs) petitions = Petition.update_trend_indexes(**kwargs) logger.info(f"Petitions trend indexes updated: {petitions}") return handler.commit(result=[p.id for p in petitions])
def populate_task(self, *args, **kwargs): with TaskHandler.execute(bind=self) as handler: kwargs = handler.getcallkwargs(Petition.populate, kwargs) petitions = Petition.populate(**kwargs) logger.info(f"Petitions onboarded: {petitions}") return handler.commit(result=[p.id for p in petitions])
def geo_poll_task(self, *args, **kwargs): with TaskHandler.execute(bind=self) as handler: kwargs = handler.getcallkwargs(Petition.poll, kwargs) records = Petition.poll(geographic=True, **kwargs) logger.info(f"Petitions base polled: {records}") return handler.commit(result=[r.petition_id for r in records])
def onboard_self_task(self, *args, **kwargs): with TaskHandler.execute(bind=self) as handler: kwargs = handler.getcallkwargs(Petition.onboard, kwargs) petition = Petition.onboard(kwargs["id"]) logger.info(f"onboarded petition id: {petition.id}") return handler.commit(result=petition, schema=PetitionSchema())
def test_task(self, *args, **kwargs): with TaskHandler.execute(bind=self) as handler: logger.info(f"running {self.name}!, kwargs: {kwargs}") logger.info("inside handler context!") return handler.commit(kwargs)