def test_run_task_not_found(manager): row = postgres.TaskRow(id=16, args={ "a": 9, "b": 3 }, targeted_object="sherlock", task_type="job") worker = task_worker.Worker(manager, "yay") with pytest.raises(exceptions.TaskNotFound): worker.run_task(row)
def test_get_tasks(connection): postgres.register_queue(connection, "queue_a") postgres.register_queue(connection, "queue_b") postgres.launch_task(connection, "queue_a", "task_1", "lock_1", {"a": "b"}) # We won't see this one because of the lock postgres.launch_task(connection, "queue_a", "task_2", "lock_1", {"c": "d"}) postgres.launch_task(connection, "queue_a", "task_3", "lock_2", {"e": "f"}) # We won't see this one because of the queue postgres.launch_task(connection, "queue_b", "task_4", "lock_3", {"g": "h"}) result = list(postgres.get_tasks(connection, "queue_a")) t1, t2 = result assert result == [ postgres.TaskRow(id=t1.id, args={"a": "b"}, targeted_object="lock_1", task_type="task_1"), postgres.TaskRow(id=t2.id, args={"e": "f"}, targeted_object="lock_2", task_type="task_3"), ]
def test_run_task_error(manager): def job(task_run, a, b): # pylint: disable=unused-argument raise ValueError("nope") task = tasks.Task(manager=manager, queue="yay", name="job") task.func = job manager.tasks = {"job": task} row = postgres.TaskRow(id=16, args={ "a": 9, "b": 3 }, targeted_object="sherlock", task_type="job") worker = task_worker.Worker(manager, "yay") with pytest.raises(exceptions.TaskError): worker.run_task(row)
def test_run_task(manager): result = [] def job(a, b): # pylint: disable=unused-argument result.append(a + b) task = tasks.Task(job, manager=manager, queue="yay", name="job") manager.tasks = {"job": task} row = postgres.TaskRow(id=16, args={ "a": 9, "b": 3 }, targeted_object="sherlock", task_type="job") worker = task_worker.Worker(manager, "yay") worker.run_task(row) assert result == [12]