Skip to content

Reject exception doesn't cause the task to fail #2944

Closed

Description

@mhnagaoka

I have a simple worker that rejects the task in case of an exception (such as ZeroDivisionError):

@app.task(bind=True, max_retries=0)
def invert(*args, **kwargs):
    try:
        x = float(kwargs['x'])
        logging.info("x=%f", x)
        result = 1.0 / float(x)
        logging.info("Result=%f", result)
    except Exception as e:
        raise Reject(e) from e

By running this worker and monitoring the outcome of the tasks using Celery Flower, I noticed that with Celery 3.1.16, the Reject exception causes the task to fail (FAILURE state), but with Celery 3.1.19 (actually 3.1.17+), the same exception does not change the task's state (it is kept in STARTED state).

I put together a simple project to help reproducing the problem: https://github.com/Arizona-Tecnologia/celery-lab

Please let me know if this is "by design" or was an unintended regression (perhaps related to #2043 ?)

Activity

  1. mhnagaoka commented on Dec 1, 2015

    @mhnagaoka
    Author

    With Celery 3.1.16, the rejected task ends in FAILURE state.

    image

    With Celery 3.1.19, the rejected task is kept in STARTED state.

    image

  2. ask commented on Dec 11, 2015

    @ask
    Contributor

    FAILURE is a final state, and rejecting a task means to requeue the task, or to let it be moved to a dead letter queue (with the possibility of ignoring the message completely), so the task must still be in a pending state.

    I added a new task-rejected event for 4.0, so that it can at least be visible in the monitor.

  3. ask commented on Dec 11, 2015

    @ask
    Contributor

    Closed by 8454428

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions