Exemple #1
0
    def start(self, args={}, subtask_key=None, workunit=None, task_id=-1, \
              callback=None, callback_args={}, errback=None, errback_args={}):
        """
        starts the task.  This will spawn the work in a separate thread.
        
        @param args - arguments to pass to task
        @param subtask_key - subtask to run
        @param workunit - key of workunit or data of workunit
        @param task_id - id of task being run
        @param callback - callback to execute after task is complete
        @param callback_args - args to pass to callback
        @param errback - call back to execute if there is an exception
        @param errback_args - arguments to pass to errback
        """

        #if this was subtask find it and execute just that subtask
        if subtask_key:
            self.logger.debug('Task - starting subtask %s' % subtask_key)
            split = subtask_key.split('.')
            subtask = self.get_subtask(split, True)
            subtask.logger = get_task_logger(self.get_worker().worker_key, \
                                             task_id, \
                                             subtask_key, workunit)
            self.logger.debug('Task - got subtask')
            self.work_deferred = threads.deferToThread(subtask._start, args, \
                                            callback, callback_args)

        elif self._status == STATUS_RUNNING:
            # only start root task if not already running
            return
        
        else:
            #else this is a normal task just execute it
            self.logger.debug('Task - starting task: %s' % self)
            self.work_deferred = threads.deferToThread(self._start, args, callback, callback_args)

        if errback:
            self.work_deferred.addErrback(errback, **errback_args)

        return 1
Exemple #2
0
 def start(self, args={}, subtask_key=None, workunit=None, task_id=-1, \
           callback=None, callback_args={}, errback=None, errback_args={}):
     """
     Start the task.
     
     The task's work will be spawned in a separate thread and run
     asynchronously.
     
     XXX Corbin: Make this return a Deferred instead of those last four
     args.
     
     :Parameters:
         args : dict
             Keyword arguments to pass to the work function
         subtask_key
             The subtask to run, or None for no subtask
         workunit
             The workunit key or data
         task_id : int
             The ID of the task being run
         callback : callable
             A callback to be called after the task completes its work
         callback_args : dict
             Keyword arguments to pass to the callback
         errback : callable
             A callback to be called if an exception happens during task
             execution
         errback_args : dict
             Arguments to pass to errback
     """
     
     #if this was subtask find it and execute just that subtask
     if subtask_key:
         self.logger.debug('Task - starting subtask %s' % subtask_key)
         split = subtask_key.split('.')
         subtask = self.get_subtask(split, True)
         subtask.logger = get_task_logger(self.get_worker().worker_key, \
                                          task_id, \
                                          subtask_key, workunit)
         self.logger.debug('Task - got subtask')
         self.work_deferred = threads.deferToThread(subtask._start, args, \
                                         callback, callback_args)
     
     elif self._status == STATUS_RUNNING:
         # only start root task if not already running
         return
     
     else:
         #else this is a normal task just execute it
         
         self.logger.debug('Task - starting task: %s' % self)
         if self.get_worker():
             self.work_deferred = threads.deferToThread(self._start, args,
                 callback, callback_args)
         else:
             # Standalone; just return the result of work()
             return self.work()
     
     if errback and self.work_deferred:
         self.work_deferred.addErrback(errback, **errback_args)
     
     return 1