1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import pulp.server.tasking.task
18
19
20 _task_complete_states = pulp.server.tasking.task.task_complete_states
21
22
23
25 """
26 Abstract base class for task queues for interface definition and typing.
27 """
28 - def enqueue(self, task, unique=False):
29 """
30 Add a task to the task queue
31 @type task: pulp.tasking.task.Task
32 @param task: Task instance
33 @type unique: bool
34 @param unique: If True, the task will only be added if there are no
35 non-finished tasks with the same method_name, args,
36 and kwargs; otherwise the task will always be added
37 @return: True if a new task was created; False if it was rejected (due to
38 the unique flag
39 """
40 raise NotImplementedError()
41
42 - def run(self, task):
43 """
44 Run a task from this task queue
45 @type task: pulp.tasking.task.Task
46 @param task: Task instance
47 """
48 raise NotImplementedError()
49
51 """
52 Mark a task run as completed
53 @type task: pulp.tasking.task.Task
54 @param task: Task instance
55 """
56 raise NotImplementedError()
57
59 """
60 Cancel a running task.
61 @type task: pulp.tasking.task.Task
62 @param task: Task instance
63 """
64 raise NotImplementedError()
65
66 - def find(self, **kwargs):
67 """
68 Find a task in this task queue. Only the oldest task in the queue will be
69 returned.
70 @type kwargs: dict
71 @param kwargs: task attributes and values as search criteria
72 @type include_finished: bool
73 @return: Task instance on success, None otherwise
74 """
75 raise NotImplementedError()
76
77 - def exists(self, task, criteria, include_finished=True):
78 """
79 Returns whether or not the given task exists in this queue. The list
80 of which attributes that will be checked on the task for equality is
81 determined by the entries in the criteria list.
82
83 @type task: Task instance
84 @param task: Values in this task will be used to test for this task's
85 existence in the queue
86
87 @type criteria: List; cannot be None
88 @param criteria: List of attribute names in the Task class; a task is
89 considered equal to the given task if the values for
90 all attributes listed in here are equal in an existing
91 task in the queue
92
93 @type include_finished: bool
94 @param include_finished: If True, finished tasks will be included in the search;
95 otherwise only running and waiting tasks are searched
96 (defaults to True)
97 """
98
99
100
101 find_criteria = {}
102 for attr_name in criteria:
103 if not hasattr(task, attr_name):
104 raise ValueError('Task has no attribute named [%s]' % attr_name)
105 find_criteria[attr_name] = getattr(task, attr_name)
106
107
108 task = self.find(**find_criteria)
109 if task is None or (not include_finished and
110 task.state in _task_complete_states):
111 return False
112 return True
113