How can I execute a CloudCode task from the app without blocking the end user?

Is it possible for a CC task to execute in the background after it has been triggered from in the app? Currently the app goes into a loading state and the user cannot do anything until the CC task is done. Should I rather use a webhook if I don’t want the app to go into that loading state?

For TypeScript apps: you can simply omit the leading await and your task will be triggered in the background.

For JavaScript apps:

  1. Using webhooks is currently the best way to enqueue a CloudCode without blocking the UI
  2. Another option is to have chained CC tasks, where your first task simply enqueues the longer running task and returns to the app quickly. While not fully async, this can greatly reduce the waiting time.

Hi @Kobie,
I’m having the same issue of getting delay from the App while CC being executed. I am generating PDF of the record saved from the App which has images attached. Some times it sends email without images. I have tried to trigger from via Webhook but this doesn’t seem to work for me.
I have put Webhook type READY to generate everytime the record is created from DB but I would prefer to send an email every time the specific field is updated. e.g Date field

Below is what I have done

  • Data Model

  • CC

export async function run() {
** if(this.source == CloudCode.WEBHOOK) {**
** //PDF generate code**
** }**
}

Thank you