def test_fail_task(dbsession, engine): task1 = Task(name='task1', active=True) dbsession.add(task1) taskflow = Taskflow() taskflow.add_task(task1) task_instance = task1.get_new_instance(run_at=datetime(2017, 6, 4, 6)) dbsession.add(task_instance) dbsession.commit() task_instance_id = task_instance.id dbsession.expunge_all() pulled_task_instances = taskflow.pull(dbsession, 'test', now=datetime(2017, 6, 4, 6, 0, 12)) pulled_task_instance = pulled_task_instances[0] assert pulled_task_instance.id == task_instance_id assert pulled_task_instance.status == 'running' assert pulled_task_instance.locked_at == datetime(2017, 6, 4, 6, 0, 12) assert pulled_task_instance.started_at == datetime(2017, 6, 4, 6, 0, 12) assert pulled_task_instance.worker_id == 'test' pulled_task_instance.fail(dbsession, taskflow, now=datetime(2017, 6, 4, 6, 0, 15)) dbsession.refresh(pulled_task_instance) assert pulled_task_instance.status == 'failed' assert pulled_task_instance.ended_at == datetime(2017, 6, 4, 6, 0, 15)
def test_queue_pull_task_run_at_order(dbsession, engine): task1 = Task(name='task1', active=True) dbsession.add(task1) taskflow = Taskflow() taskflow.add_task(task1) task_instance1 = task1.get_new_instance(run_at=datetime(2017, 6, 4, 6, 0, 5)) task_instance2 = task1.get_new_instance(run_at=datetime(2017, 6, 4, 6, 0, 10)) dbsession.add(task_instance1) dbsession.add(task_instance2) dbsession.commit() sooner_task_instance_id = task_instance1.id later_task_instance_id = task_instance2.id dbsession.expunge_all() pulled_task_instances = taskflow.pull(dbsession, 'test', max_tasks=1, now=datetime(2017, 6, 4, 6, 0, 12)) pulled_task_instance = pulled_task_instances[0] assert pulled_task_instance.id == sooner_task_instance_id assert pulled_task_instance.status == 'running' assert pulled_task_instance.locked_at == datetime(2017, 6, 4, 6, 0, 12) assert pulled_task_instance.started_at == datetime(2017, 6, 4, 6, 0, 12) assert pulled_task_instance.worker_id == 'test' pulled_task_instances = taskflow.pull(dbsession, 'test', max_tasks=1, now=datetime(2017, 6, 4, 6, 0, 12)) pulled_task_instance = pulled_task_instances[0] assert pulled_task_instance.id == later_task_instance_id assert pulled_task_instance.status == 'running' assert pulled_task_instance.locked_at == datetime(2017, 6, 4, 6, 0, 12) assert pulled_task_instance.started_at == datetime(2017, 6, 4, 6, 0, 12) assert pulled_task_instance.worker_id == 'test'