Beispiel #1
0
    def create_message(self, task):
        task_str = self.task_to_string(type(task))
        if task_str not in self._registry:
            raise HueyException('%s not found in TaskRegistry' % task_str)

        # Remove the "task" instance from any arguments before serializing.
        if task.kwargs and 'task' in task.kwargs:
            task.kwargs.pop('task')

        on_complete = None
        if task.on_complete is not None:
            on_complete = self.create_message(task.on_complete)

        on_error = None
        if task.on_error is not None:
            on_error = self.create_message(task.on_error)

        return Message(
            task.id,
            task_str,
            task.eta,
            task.retries,
            task.retry_delay,
            task.priority,
            task.args,
            task.kwargs,
            on_complete,
            on_error)
Beispiel #2
0
    def get_raw_result(self,
                       blocking=False,
                       timeout=None,
                       backoff=1.15,
                       max_delay=1.0,
                       revoke_on_timeout=False,
                       preserve=False):
        if not blocking:
            res = self._get(preserve)
            if res is not EmptyData:
                return res
        else:
            start = time_clock()
            delay = .1
            while self._result is EmptyData:
                if timeout and time_clock() - start >= timeout:
                    if revoke_on_timeout:
                        self.revoke()
                    raise HueyException('timed out waiting for result')
                if delay > max_delay:
                    delay = max_delay
                if self._get(preserve) is EmptyData:
                    time.sleep(delay)
                    delay *= backoff

            return self._result
Beispiel #3
0
 def string_to_task(self, task_str):
     if task_str not in self._registry:
         raise HueyException('%s not found in TaskRegistry' % task_str)
     return self._registry[task_str]