def test_cleanup_inconsistent_task(self, notify, active_tasks, considered_jobs, reapable_jobs, running_tasks, waiting_tasks, mocker): tm = TaskManager() tm.get_running_tasks = mocker.Mock(return_value=(running_tasks, waiting_tasks)) tm.get_active_tasks = mocker.Mock(return_value=active_tasks) tm.cleanup_inconsistent_celery_tasks() for j in considered_jobs: if j not in reapable_jobs: j.save.assert_not_called() assert notify.call_count == 4 notify.assert_has_calls( [mock.call(j, 'failed') for j in reapable_jobs], any_order=True) for j in reapable_jobs: j.websocket_emit_status.assert_called_once_with('failed') assert j.status == 'failed' assert j.job_explanation == ( 'Task was marked as running in Tower but was not present in Celery, so it has been marked as failed.' )
def test_get_running_tasks(self, all_jobs): tm = TaskManager() # Ensure the query grabs the expected jobs execution_nodes_jobs, waiting_jobs = tm.get_running_tasks() assert 'host1' in execution_nodes_jobs assert 'host2' in execution_nodes_jobs assert 'host3_split' in execution_nodes_jobs assert all_jobs[3] in execution_nodes_jobs['host1'] assert all_jobs[6] in execution_nodes_jobs['host2'] assert all_jobs[7] in execution_nodes_jobs['host2'] assert all_jobs[9] in execution_nodes_jobs['host3_split'] assert all_jobs[10] in execution_nodes_jobs['host4_offline'] assert all_jobs[11] not in execution_nodes_jobs['host1'] assert all_jobs[2] in waiting_jobs assert all_jobs[4] in waiting_jobs assert all_jobs[5] in waiting_jobs assert all_jobs[8] in waiting_jobs