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

Is there a way to update the state of a task? #45

Closed
danielmichalichyn opened this issue Feb 9, 2021 · 3 comments
Closed

Is there a way to update the state of a task? #45

danielmichalichyn opened this issue Feb 9, 2021 · 3 comments

Comments

@danielmichalichyn
Copy link
Contributor

In Celery Python we have the method to update the state of a task, like below:

def task(self):
    try:
        raise ValueError('Some error')
    except Exception as ex:
        self.update_state(state=states.FAILURE, meta={'custom': '...'})
        raise Ignore()

Is there any equivalent method in Celery Node?
My goal is to update the state of the task to FAILURE in case an error occurs in my worker.

@danielmichalichyn
Copy link
Contributor Author

I've found out that when we throw an Error from the celery.node worker, the state of the Task is saved as 'SUCCESS'. This is because the state of the task is hard coded inside the taskHandler, when we call storeResult.
Maybe we can implement a CATCH in the taskPromise, so when a error is thrown from our worker, we can store the result as 'FAILURE'?
This is something that is suitable for the celery.node project, if yes, i can make a PR for this.

@actumn
Copy link
Owner

actumn commented Mar 2, 2021

Hi. Thank you for reporting the issue.
You're right. It would be greatly appreciated if you make a PR.

Thank you.

@danielmichalichyn
Copy link
Contributor Author

I've submitted a PR in order to solve this, i'm closing this issue.

actumn added a commit that referenced this issue Mar 13, 2021
…he task is stores as FAILURE. (#49)

* Added catch on taskHandler. When an error is raised from the worker, the catch method will store a FAILURE task.

* Alter package.json

* Correcting package.json

* Added post install to package.json

* Alter dist in package.json

* Alter package.json again...

* Added dist folder to project

* Altering npm ignore and package.json

* Modifiying files for PR to cover issue #45

* Removed dist for PR

* Alter test result for FAILURE task

* Update src/backends/amqp.ts

* Update src/backends/redis.ts

* Update redis.ts

Co-authored-by: Daniel Henrique Michalichyn <daniel.henrique@st-one.io>
Co-authored-by: SunMyeong Lee <actumn814@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants