mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 15:36:04 -03:30
use standard type string algorithm in scheduler
This commit is contained in:
@@ -18,6 +18,7 @@ from awx.main.models import * # noqa
|
|||||||
#from awx.main.scheduler.dag_simple import SimpleDAG
|
#from awx.main.scheduler.dag_simple import SimpleDAG
|
||||||
from awx.main.scheduler.dag_workflow import WorkflowDAG
|
from awx.main.scheduler.dag_workflow import WorkflowDAG
|
||||||
from awx.main.utils.pglock import advisory_lock
|
from awx.main.utils.pglock import advisory_lock
|
||||||
|
from awx.main.utils import get_type_for_model
|
||||||
from awx.main.signals import disable_activity_stream
|
from awx.main.signals import disable_activity_stream
|
||||||
|
|
||||||
from awx.main.scheduler.dependency_graph import DependencyGraph
|
from awx.main.scheduler.dependency_graph import DependencyGraph
|
||||||
@@ -64,22 +65,6 @@ class TaskManager():
|
|||||||
key=lambda task: task.created)
|
key=lambda task: task.created)
|
||||||
return all_tasks
|
return all_tasks
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_node_type(cls, obj):
|
|
||||||
if type(obj) == Job:
|
|
||||||
return "job"
|
|
||||||
elif type(obj) == AdHocCommand:
|
|
||||||
return "ad_hoc_command"
|
|
||||||
elif type(obj) == InventoryUpdate:
|
|
||||||
return "inventory_update"
|
|
||||||
elif type(obj) == ProjectUpdate:
|
|
||||||
return "project_update"
|
|
||||||
elif type(obj) == SystemJob:
|
|
||||||
return "system_job"
|
|
||||||
elif type(obj) == WorkflowJob:
|
|
||||||
return "workflow_job"
|
|
||||||
return "unknown"
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Tasks that are running and SHOULD have a celery task.
|
Tasks that are running and SHOULD have a celery task.
|
||||||
'''
|
'''
|
||||||
@@ -190,10 +175,10 @@ class TaskManager():
|
|||||||
from awx.main.tasks import handle_work_error, handle_work_success
|
from awx.main.tasks import handle_work_error, handle_work_success
|
||||||
|
|
||||||
task_actual = {
|
task_actual = {
|
||||||
'type':self.get_node_type(task),
|
'type': get_type_for_model(type(task)),
|
||||||
'id': task.id,
|
'id': task.id,
|
||||||
}
|
}
|
||||||
dependencies = [{'type': self.get_node_type(t), 'id': t.id} for t in dependent_tasks]
|
dependencies = [{'type': get_type_for_model(type(t)), 'id': t.id} for t in dependent_tasks]
|
||||||
|
|
||||||
error_handler = handle_work_error.s(subtasks=[task_actual] + dependencies)
|
error_handler = handle_work_error.s(subtasks=[task_actual] + dependencies)
|
||||||
success_handler = handle_work_success.s(task_actual=task_actual)
|
success_handler = handle_work_success.s(task_actual=task_actual)
|
||||||
|
|||||||
@@ -8,6 +8,15 @@ from uuid import uuid4
|
|||||||
|
|
||||||
from awx.main.utils import common
|
from awx.main.utils import common
|
||||||
|
|
||||||
|
from awx.main.models import (
|
||||||
|
Job,
|
||||||
|
AdHocCommand,
|
||||||
|
InventoryUpdate,
|
||||||
|
ProjectUpdate,
|
||||||
|
SystemJob,
|
||||||
|
WorkflowJob
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('input_, output', [
|
@pytest.mark.parametrize('input_, output', [
|
||||||
({"foo": "bar"}, {"foo": "bar"}),
|
({"foo": "bar"}, {"foo": "bar"}),
|
||||||
@@ -27,3 +36,16 @@ def test_set_environ():
|
|||||||
assert set(os.environ.keys()) - set(old_environ.keys()) == set([key])
|
assert set(os.environ.keys()) - set(old_environ.keys()) == set([key])
|
||||||
assert os.environ == old_environ
|
assert os.environ == old_environ
|
||||||
assert key not in os.environ
|
assert key not in os.environ
|
||||||
|
|
||||||
|
|
||||||
|
# Cases relied on for scheduler dependent jobs list
|
||||||
|
@pytest.mark.parametrize('model,name', [
|
||||||
|
(Job, 'job'),
|
||||||
|
(AdHocCommand, 'ad_hoc_command'),
|
||||||
|
(InventoryUpdate, 'inventory_update'),
|
||||||
|
(ProjectUpdate, 'project_update'),
|
||||||
|
(SystemJob, 'system_job'),
|
||||||
|
(WorkflowJob, 'workflow_job')
|
||||||
|
])
|
||||||
|
def test_get_type_for_model(model, name):
|
||||||
|
assert common.get_type_for_model(model) == name
|
||||||
|
|||||||
Reference in New Issue
Block a user