Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support retry on failed tasks #64

Open
imranariffin opened this issue Jul 24, 2023 · 0 comments
Open

Support retry on failed tasks #64

imranariffin opened this issue Jul 24, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@imranariffin
Copy link
Owner

imranariffin commented Jul 24, 2023

Retry failed task if specified in task definition or in task call

import asyncio

from aiotaskq.task import task


class SomeException(Exception):
    pass


class SomeOtherException(Exception):
    pass


@task(retry=(3, SomeException))
def some_task_1():
    raise SomeException


@task()
def some_task_2():
    raise SomeException


async def apply_tasks():
    # Will be retried 3 times, as specified in task definition
    try:
        await some_task_1.apply_async()
    except SomeException as e:
        assert e.aiotaskq.retries == 3

    # Will be retried 2 times, as specified in task call (retry configuration from task
    # definition has been overridden)
    try:
        await some_task_1.retry((1, SomeException)).apply_async()
    except SomeException as e:
        assert e.aiotaskq.retries == 2

    # Will NOT be retried (retry configuration from task definition is overridden)
    try:
        await some_task_1.retry((1, SomeOtherException)).apply_async()
    except SomeException as e:
        assert e.aiotaskq.retries == 0
    except SomeOtherException as e:
        assert False, "Should not reach here"

    # Will be retried 1 time, as specified in task call
    try:
        await some_task_2.retry((1, SomeException)).apply_async()
    except SomeException as e:
        assert e.aiotaskq.retries == 1


if __name__ == "__main__":
    asyncio.run(apply_tasks())
@imranariffin imranariffin added the enhancement New feature or request label Jul 24, 2023
imranariffin added a commit that referenced this issue Dec 3, 2023
* Formalize serialization and deserialization
* Serialize & deserialize exceptions correctly
* Encapsulate retry & retry_on in a new dict 'options'
* Implement serde for AsyncResult
* Ensure generated file deleted after test
* Add jsonpickle to toml file
* Exclude `if TYPE_CHECKING:` from coverage
* Add test for singleton
* Add logging for worker
* Wrap all constants inside `Config` class
imranariffin added a commit that referenced this issue Dec 3, 2023
For documentation, see:
1. Docstring of `task.task`
2. Tests in `tests.test_task` e.g. `test_retry_as_per_task_definition`
3. Sample usages in `tests.apps.simple_app` e.g. `append_to_file`

Changelist:

* Formalize serialization and deserialization
* Serialize & deserialize exceptions correctly
* Encapsulate retry & retry_on in a new dict 'options'
* Implement serde for AsyncResult
* Ensure generated file deleted after test
* Add jsonpickle to toml file
* Exclude `if TYPE_CHECKING:` from coverage
* Add test for singleton
* Add logging for worker
* Wrap all constants inside `Config` class
imranariffin added a commit that referenced this issue Dec 3, 2023
For documentation, see:
1. Docstring of `task.task`
2. Tests in `tests.test_task` e.g. `test_retry_as_per_task_definition`
3. Sample usages in `tests.apps.simple_app` e.g. `append_to_file`

Changelist:

* Formalize serialization and deserialization
* Serialize & deserialize exceptions correctly
* Encapsulate retry & retry_on in a new dict 'options'
* Implement serde for AsyncResult
* Ensure generated file deleted after test
* Add jsonpickle to toml file
* Exclude `if TYPE_CHECKING:` from coverage
* Add test for singleton
* Add logging for worker
* Wrap all constants inside `Config` class

Signed-off-by: Imran Ariffin <ariffin.imran@gmail.com>
imranariffin added a commit that referenced this issue Dec 3, 2023
For documentation, see:
1. Docstring of `task.task`
2. Tests in `tests.test_task` e.g. `test_retry_as_per_task_definition`
3. Sample usages in `tests.apps.simple_app` e.g. `append_to_file`

Changelist:

* Formalize serialization and deserialization
* Serialize & deserialize exceptions correctly
* Encapsulate retry & retry_on in a new dict 'options'
* Implement serde for AsyncResult
* Ensure generated file deleted after test
* Add jsonpickle to toml file
* Exclude `if TYPE_CHECKING:` from coverage
* Add test for singleton
* Add logging for worker
* Wrap all constants inside `Config` class

Signed-off-by: Imran Ariffin <ariffin.imran@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant