Package pulp :: Package server :: Package tasking :: Package queue :: Module base
[hide private]
[frames] | no frames]

Source Code for Module pulp.server.tasking.queue.base

  1  #!/usr/bin/env python 
  2  # -*- coding: utf-8 -*- 
  3  # 
  4  # Copyright © 2010 Red Hat, Inc. 
  5  # 
  6  # This software is licensed to you under the GNU General Public License, 
  7  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
  8  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
  9  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
 10  # along with this software; if not, see 
 11  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
 12  # 
 13  # Red Hat trademarks are not licensed under GPLv2. No permission is 
 14  # granted to use or replicate Red Hat trademarks that are incorporated 
 15  # in this software or its documentation. 
 16   
 17  import pulp.server.tasking.task 
 18   
 19   
 20  _task_complete_states = pulp.server.tasking.task.task_complete_states 
 21   
 22  # base task queue ------------------------------------------------------------- 
 23   
24 -class TaskQueue(object):
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
50 - def complete(self, task):
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
58 - def cancel(self, task):
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 # Convert the list of attributes to check into a criteria dict used 100 # by the storage API, using the task to test as the values 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 # Use the find functionality to determine if a task matches 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