Accesing Job object from within girder-worker task


#1

Hi!
Is there a way to access a Job associated with a girder-worker task from within that task? Specifically, I’d like to update Job’s progress message.
Cheers,
Kacper


#2

I think if your task is a bound task, then it should have access to a couple of things:

  1. An instance of Girder Client, using the girder_client attribute of your bound task (self.girder_client). This may or may not be authenticated already.
  2. An instance of a JobManager, which has methods for updating progress (self.job_manager).

I’m a bit fuzzy on exactly what qualifies tasks for receiving both of those things, they’re attached in the Celery task-prerun signal here. @Chris_Kotfila knows a bit more about the details.


#3

A quick code example of what @danlamanna was referring to:

from girder_worker.app import app

@app.task(bind=True)
def my_task(self, *args, **kwargs):
    self.job_manager.updateProgress(message='starting', total=100, current=0)
    # do stuff

#4

Thanks a lot!