2

I love the notion of tasks, especially for large processes, but I've found that their isn't a lot of documentation around it which makes trouble shooting them via an authoritative source difficult.

A few things I've found out that I had misconceptions on:

  1. A task is one request, no matter how many steps it has, that runs in the background.
  2. Sub tasks are all part of that initial task's one request
  3. Since a task is a single request it is subjected to the same PHP Limitations that a normal request would be (i.e., memory limit) (this really comes into play when important large amounts of data in a dev environment because there's a lot of information that's being logged via a single request -- could be 100s of MB of log files in request

Some things I'm still confused about:

  1. Does a task run with a separate session ID and thread than the browser that initiated the task via the CP request? I've noticed using the Power Nap plugin that if I initiate the running of task via a CP request I can navigate to other pages while the task is still running, but with other plugins that import Commerce data, I have to wait until the entire import is done before I can navigate to another page.

  2. Do multiple queued tasks all get a single request or are they lumped into a single request?

  3. If I need to insert thousands of entries is it more performant / desirable to place all entries in a single task or queue a task for each entry?

I'm sure their will be more, but I definitely think a single location for figuring out the benefits / use cases / pitfalls of Craft Tasks will be hugely beneficial.

Thanks in advance for the discussion.

3

One pitfall: In Craft 2 I've had troubles with a script that created thousands of entries.

The CP totally hung because it could not process the numerous tasks that were created (tasks of the like 'updateUri' ..). This was probably due to time limits and memory consumption; tasks were not processed anymore.

To solve that I created a task runner plugin, that processes a limited amount of tasks in the background through a cron job, and disables task execution on control panel access.

  • Great solution! Looks like a nice plugin. I'll definitely dig into it further. Thanks for the resource. – Peter Tell Aug 11 '17 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.