Exemplo n.º 1
0
    def _run_task(self, key, version, task_class, module_search_path, args={},
            subtask_key=None, workunit=None, main_worker=None, task_id=None,
            callback=None):
        """
        Runs a task on this worker
        
        @param key - key identifying task to run
        @param version - version of task to run.
        @param task_class - class instance of the task
        @param module_search_path - ????????????????
        @param args - kwargs that will be passed to the Task.start()
        @param subtask_key - key identifying subtask to run
        @param workunit - key to data, or data to processed
        @param main_worker - key for the main worker of this task
        @param task_id - ID of the task instance
        """
        logger.info('RunTask:  key=%s  args=%s  sub=%s  w=%s  main=%s' \
            % (key, '--', subtask_key, workunit, main_worker))
        # Register task with worker
        with self._lock:
            if not key:
                return "FAILURE: NO TASK KEY SPECIFIED"
            # save what worker is running
            self._task = key
            self._subtask = subtask_key

        # If args is a string, it may be unicode instead of str. This is a
        # Django issue. Try to make everybody happy by treating the string as
        # JSON.

        # This is almost certainly the wrong thing to do, but it's historical.
        try:
            clean_args = dict(
                    (str(k), v) for k, v in
                    simplejson.loads(args).iteritems()
            )
        except:
            clean_args = args

        # only create a new task instance if this is the root task.  Otherwise
        # subtasks will be created within the structure of the task.
        if not self._task_instance:
            self._task_instance = task_class()
            self._task_instance.parent = self
            if not subtask_key:
                self._task_instance.logger = get_task_logger(self.worker_key, \
                                                                task_id)

        # start the task.  If this is actually a subtask, then the task is
        # responsible for starting the subtask instead of the main task
        return self._task_instance.start(clean_args, subtask_key, workunit,
                        task_id, \
                        callback=callback,
                        callback_args = {'workunit':workunit},
                        errback=callback,
                        errback_args={'workunit':workunit, 'failed':True})
Exemplo n.º 2
0
    def _run_task(self, key, version, task_class, module_search_path, args={},
            subtask_key=None, workunit=None, main_worker=None, task_id=None,
            callback=None):
        """
        Runs a task on this worker
        
        @param key - key identifying task to run
        @param version - version of task to run.
        @param task_class - class instance of the task
        @param module_search_path - ????????????????
        @param args - kwargs that will be passed to the Task.start()
        @param subtask_key - key identifying subtask to run
        @param workunit - key to data, or data to processed
        @param main_worker - key for the main worker of this task
        @param task_id - ID of the task instance
        """
        logger.info('RunTask:  key=%s  args=%s  sub=%s  w=%s  main=%s' \
            % (key, '--', subtask_key, workunit, main_worker))

        # Register task with worker
        with self._lock:
            if not key:
                return "FAILURE: NO TASK KEY SPECIFIED"
            # save what worker is running
            self.__task = key
            self.__subtask = subtask_key

        # process args to make sure they are no longer unicode.  This is an
        # issue with the args coming through the django frontend.
        clean_args = {}
        args = simplejson.loads(args)
        if args:
            for arg_key, arg_value in args.items():
                clean_args[arg_key.__str__()] = arg_value

        # only create a new task instance if this is the root task.  Otherwise
        # subtasks will be created within the structure of the task.
        if not self.__task_instance:
            self.__task_instance = task_class()
            self.__task_instance.parent = self
            if not subtask_key:
                self.__task_instance.logger = get_task_logger(self.worker_key, \
                                                                task_id)

        # start the task.  If this is actually a subtask, then the task is
        # responsible for starting the subtask instead of the main task
        return self.__task_instance.start(clean_args, subtask_key, workunit,
                        task_id, \
                        callback=callback,
                        callback_args = {'workunit':workunit},
                        errback=callback,
                        errback_args={'workunit':workunit, 'failed':True})