Example #1
0
    def queue_task(self, task_key, args={}, subtask_key=None):
        """
        Queue a task to be run.  All task requests come through this method.  It saves their
        information in the database.  If the cluster has idle resources it will start the task
        immediately, otherwise it will queue the task until it is ready.
        """
        logger.info('Task:%s:%s - Queued:  %s' % (task_key, subtask_key, args))

        #create a TaskInstance instance and save it
        task_instance = TaskInstance()
        task_instance.task_key = task_key
        task_instance.subtask_key = subtask_key
        task_instance.args = simplejson.dumps(args)
        task_instance.save()

        #queue the task and signal attempt to start it
        with self._lock_queue:
            self._queue.append(task_instance)
        self.advance_queue()

        return task_instance
Example #2
0
    def setUp(self):

        self.tasks = ['TestTask','TestContainerTask','TestParallelTask']
        self.completion = {}

        for task in self.tasks:
            self.completion[task] = None

        for task in self.tasks [:2]:
            #queued tasks
            task_instance = TaskInstance()
            task_instance.task_key=task
            task_instance.save()

            #running tasks
            task_instance = TaskInstance()
            task_instance.task_key=task
            task_instance.started = time.strftime('%Y-%m-%d %H:%M:%S')
            task_instance.save()

            #finished tasks
            task_instance = TaskInstance()
            task_instance.task_key=task
            task_instance.started = time.strftime('%Y-%m-%d %H:%M:%S')
            completed_time = time.strftime('%Y-%m-%d %H:%M:%S')
            task_instance.completed = completed_time
            task_instance.save()
            self.completion[task] = completed_time

            #failed tasks
            task_instance = TaskInstance()
            task_instance.task_key=task
            task_instance.started = time.strftime('%Y-%m-%d %H:%M:%S')
            task_instance.completion_type = -1
            task_instance.save()