I'd like to extend the djcelery taskmeta
table, for example I have a scheduled task that returns an integer value.
I'd like to add a field to store this value so I can graph this data along with the date_done
field in the taskmeta
table.
I tried to create a new model and making a foreignkey relationship with the taskmeta
table, and inside my task add a row in this new table based on the task_id
.
But I guess while the task executes, I won't be able to do, as I assume the taskmeta
data has not been saved at this point, ie:
if mover.request.id:
try:
task = TaskMeta.objects.get(task_id=mover.request.id)
extend_task_info = TaskExtended(task=task)
extend_task_info.save()
except ObjectDoesNotExist:
logger.error('Task ID: %s not in the DB' % mover.request.id)
Addition of task code:
@task()
def mover():
for root, dirs, files in os.walk(src_dir):
path = root.split('/')
for file in files:
counter = process_file(os.path.join(root, file))
if mover.request.id:
try:
tn = TaskMeta.objects.get(task_id=mover.request.id)
extend_task_info = TaskExtended(task=task)
extend_task_info.counter = counter
extend_task_info.save()
except ObjectDoesNotExist:
logger.error('Task ID: %s not in the DB' % mover.request.id)