def create_task_schedule( name, task, cron=None, start_time=None, args=None, kwargs=None, options=None, enabled=None, task_type=None, commit=True, session=None, ): schedule = TaskSchedule( name=name, task=task, cron=cron, start_time=start_time, args=args or [], kwargs=kwargs or {}, options=options or {}, enabled=enabled, task_type=task_type, ) session.add(schedule) if commit: session.commit() else: session.flush() schedule.id return schedule
def __init__(self, model: TaskSchedule, app=None): self.app = app or current_app self.app.now = datetime.now self.schedule = model.schedule self.name = model.name self.task = model.task try: self.args = model.args or [] self.kwargs = model.kwargs or {} options = model.options or {} except ValueError as exc: logger.exception( "Removing schedule %s for argument deseralization error: %r", self.name, exc, ) self._disable(model) self.options = {"shadow": self.name} for option in self.valid_options: if option in options: self.options[option] = options[option] self.total_run_count = model.total_run_count self.model = model if not model.last_run_at: model.last_run_at = self._default_now() self.last_run_at = model.last_run_at
def exec_demo_set_up(): with DBSession() as session: environment = environment_logic.create_environment( name="demo_environment", description="Demo environment", image="", public=True, commit=False, session=session, ) local_db_conn = "sqlite:///demo/demo_data.db" metastore_id = QueryMetastore.create( { "name": "demo_metastore", "metastore_params": {"connection_string": local_db_conn,}, "loader": "SqlAlchemyMetastoreLoader", "acl_control": {}, }, commit=False, session=session, ).id engine_id = QueryEngine.create( { "name": "sqlite", "description": "SQLite Engine", "language": "sqlite", "executor": "sqlalchemy", "executor_params": {"connection_string": local_db_conn,}, "environment_id": environment.id, "metastore_id": metastore_id, }, commit=False, session=session, ).id logic.add_query_engine_to_environment( environment.id, engine_id, commit=False, session=session ) task_schedule_id = TaskSchedule.create( { "name": "update_metastore_{}".format(metastore_id), "task": "tasks.update_metastore.update_metastore", "cron": "0 0 * * *", "args": [metastore_id], "task_type": "prod", "enabled": True, }, # commit=False, session=session, ).id schedule_logic.run_and_log_scheduled_task( scheduled_task_id=task_schedule_id, wait_to_finish=True, session=session ) golden_table = metastore_logic.get_table_by_name( schema_name="main", name="world_happiness_2019", metastore_id=metastore_id, session=session, ) if golden_table: metastore_logic.update_table( id=golden_table.id, golden=True, session=session ) metastore_logic.update_table_information( data_table_id=golden_table.id, description="The World Happiness Report is a landmark survey of the state of global happiness. The first report was published in 2012, the second in 2013, the third in 2015, and the fourth in the 2016 Update. The World Happiness 2017, which ranks 155 countries by their happiness levels, was released at the United Nations at an event celebrating International Day of Happiness on March 20th. The report continues to gain global recognition as governments, organizations and civil society increasingly use happiness indicators to inform their policy-making decisions. Leading experts across fields – economics, psychology, survey analysis, national statistics, health, public policy and more – describe how measurements of well-being can be used effectively to assess the progress of nations. The reports review the state of happiness in the world today and show how the new science of happiness explains personal and national variations in happiness.", session=session, ) demo_logic.create_demo_table_stats( table_id=golden_table.id, uid=current_user.id, session=session ) score_column = metastore_logic.get_column_by_name( name="Score", table_id=golden_table.id, session=session ) demo_logic.create_demo_table_column_stats( column_id=score_column.id, uid=current_user.id, session=session ) schedule_logic.run_and_log_scheduled_task( scheduled_task_id=task_schedule_id, session=session ) demo_logic.create_demo_lineage(metastore_id, current_user.id, session=session) data_doc_id = demo_logic.create_demo_data_doc( environment_id=environment.id, engine_id=engine_id, uid=current_user.id, session=session, ) if data_doc_id: session.commit() return { "environment": environment.name, "data_doc_id": data_doc_id, }
def delete_task_schedule(id,): TaskSchedule.delete(id)
def get_all_tasks(): return TaskSchedule.get_all()
def get_schedule_by_name(name): return TaskSchedule.get(name=name)