Ejemplo n.º 1
0
def create_task(**kwargs):
    task = Task()
    default_function_name = 'tests.fixtures.do_nothing'
    task.function_name = kwargs.get('function_name', default_function_name)
    task.function_args = kwargs.get('function_args', '{}')
    task.due_at = kwargs.get('due_at', now())

    if 'name' in kwargs:
        task.name = kwargs['name']
    if 'status' in kwargs:
        task.status = kwargs['status']
    if 'retries' in kwargs:
        task.retries = kwargs['retries']
    if 'max_retries' in kwargs:
        task.max_retries = kwargs['max_retries']
    if 'retry_delay' in kwargs:
        task.retry_delay = kwargs['retry_delay']
    if 'retry_backoff' in kwargs:
        task.retry_backoff = kwargs['retry_backoff']
    if 'retry_backoff_factor' in kwargs:
        task.retry_backoff_factor = kwargs['retry_backoff_factor']

    task.save()

    return task
Ejemplo n.º 2
0
def create_task(**kwargs):
    task = Task()
    default_function_name = 'tests.fixtures.do_nothing'
    task.function_name = kwargs.get('function_name', default_function_name)
    task.function_args = kwargs.get('function_args', '{}')
    task.due_at = kwargs.get('due_at', now())

    if 'name' in kwargs:
        task.name = kwargs['name']
    if 'status' in kwargs:
        task.status = kwargs['status']
    if 'retries' in kwargs:
        task.retries = kwargs['retries']
    if 'max_retries' in kwargs:
        task.max_retries = kwargs['max_retries']
    if 'retry_delay' in kwargs:
        task.retry_delay = parse_timedelta(kwargs['retry_delay'])
    if 'retry_backoff' in kwargs:
        task.retry_backoff = kwargs['retry_backoff']
    if 'retry_backoff_factor' in kwargs:
        task.retry_backoff_factor = kwargs['retry_backoff_factor']
    if 'timeout' in kwargs:
        task.timeout = parse_timedelta(kwargs['timeout'], nullable=True)

    task.save()

    return task
Ejemplo n.º 3
0
    def test_tasks_arguments_decoding_args(self):
        """The function positional args are properly decoded when using decode_function_args()."""
        task = Task()
        task.due_at = now()
        task.function_name = "tests.fixtures.do_nothing"
        task.function_args = '{"__positional_args__": [4, true, "banana"]}'
        task.save()

        expected = ([4, True, "banana"], {})
        self.assertEqual(task.decode_function_args(), expected)
Ejemplo n.º 4
0
    def test_tasks_arguments_decoding_mixed_args(self):
        """The function parameters are properly decoded when using decode_function_args()."""
        task = Task()
        task.due_at = now()
        task.function_name = "tests.fixtures.do_nothing"
        task.function_args = '{"cheese": "blue", "fruits_count": 8, "__positional_args__": [7, "orange"]}'
        task.save()

        expected = ([7, "orange"], {
            "cheese": "blue",
            "fruits_count": 8
        })
        self.assertEqual(task.decode_function_args(), expected)
Ejemplo n.º 5
0
    def test_tasks_arguments_decoding_kwargs(self):
        """The function kwargs are properly decoded when using decode_function_args()."""
        task = Task()
        task.due_at = now()
        task.function_name = "tests.fixtures.do_nothing"
        task.function_args = '{"cheese": "blue", "fruits_count": 8}'
        task.save()

        expected = ([], {
            "cheese": "blue",
            "fruits_count": 8
        })
        self.assertEqual(task.decode_function_args(), expected)