Chained background jobs

From frappeframework docs:

def long_job(arg1, arg2):
    frappe.publish_realtime('msgprint', 'Starting long job...')
    # this job takes a long time to process
    frappe.publish_realtime('msgprint', 'Ending long job...')

def enqueue_long_job(arg1, args2):
    enqueue('myapp.mymodule.long_job', arg1=arg1, arg2=arg2)

Can we chain the function like:

def long_job(arg1, arg2):
    frappe.publish_realtime('msgprint', 'Starting long job...')
    # this job takes a long time to process
    frappe.publish_realtime('msgprint', 'Ending long job...')
    also_long_job(arg1, arg2)

def also_long_job(arg1, arg2):
    frappe.publish_realtime('msgprint', 'Starting also long job...')
    # this job takes a long time to process
    frappe.publish_realtime('msgprint', 'Ending also long job...')

def enqueue_long_job(arg1, args2):
    enqueue('myapp.mymodule.long_job', arg1=arg1, arg2=arg2)

Will the also_long_job also included in the same background job?

What you’ve done is called another function from enqueued function and it’s perfectly legal.

Frappe uses RQ for background jobs. Just makes sure your function will be completed in the specified timeout. These are default timeouts(seconds) for 3 queues.

queue_timeout = {
	'long': 1500,
	'default': 300,
	'short': 300
}
1 Like