<p>Sub-tasks can only be initiated by the parent task, and they will only visually look like a sub-task if they are actually sub-tasks.</p>

<p>It’s also not possible to change the settings of an already-running task, at least without manually checking for new settings in your task.</p>

<p>So, your parent task’s <code>getStep()</code> function would need to do its own checking to see if it should be running a sub-task, somehow, and then conditionally call <code>$this-&gt;runSubTask()</code>.</p>

CC BY-SA 3.0
2014-06-26T12:58:02.383Z
Sorry..., I think my question was confusing (note-to-self: never ask questions when tired). I hope it's clearer now, could you take a look again? Thanks a lot. :)
Victor
CC BY-SA 3.0
2014-06-26T19:17:23.397Z
Got it. Just updated my answer.
Brandon Kelly
CC BY-SA 3.0
2014-06-26T19:19:25.660Z
Thanks. But is it possible to pass data to a running task? Or would I need to use a Record and check on each run?
Victor
CC BY-SA 3.0
2014-06-26T19:28:39.897Z
@VictorIn Updated once again.
Brandon Kelly
CC BY-SA 3.0
2014-06-26T05:41:24.563Z
2014-06-26T19:28:28.550Z
2014-06-26T19:28:28.550Z
Brandon Kelly
<p>I have a plugin which creates a task every time a specify form is submited. Now I want to create a WrapperTask and run each of those tasks as a subTask:</p>

<p><img src="https://i.sstatic.net/4BfXm.jpg" alt="Craft Task with running sub tasks"></p>

<p>I know that I can create a sub-task within the WrapperTask by using <code>$this-&gt;runSubTask</code>, but how can I add a subTask to an already running WrapperTask from outside (the service for example)? Or at least send a new settings-array to an already running Task?</p>

<p><strong>Example:</strong></p>

<ol>
<li>User submits form</li>
<li>Service creates WrapperTask</li>
<li>Service adds subTask to WrapperTask</li>
<li>Nothing happens for some time</li>
<li>User submits form again</li>
<li>Service checks if WrapperTask is still running, and adds subTask</li>
</ol>

<p>.</p>

<p>If that's not possible, can I at least show them visually as subtasks of my plugin in the task-list?</p>

CC BY-SA 3.0
2014-06-26T22:12:33.587Z
I rolled you over 2k. :-)
nicael
CC BY-SA 3.0
2014-06-26T22:17:20.187Z
Suggesting to read about your new [privilege](http://craftcms.stackexchange.com/help/privileges/moderator-tools)
nicael
<plugin-development><tasks>
How to add a subTask to an already running Task?
# How to add a subTask to an already running Task?

(Asked by: username_0 on 2014-06-25)

I have a plugin which creates a task every time a specify form is submited. Now I want to create a WrapperTask and run each of those tasks as a subTask:

![Craft Task with running sub tasks](https://i.sstatic.net/4BfXm.jpg)

I know that I can create a sub-task within the WrapperTask by using `$this->runSubTask`, but how can I add a subTask to an already running WrapperTask from outside (the service for example)? Or at least send a new settings-array to an already running Task?

**Example:**

1. User submits form
2. Service creates WrapperTask
3. Service adds subTask to WrapperTask
4. Nothing happens for some time
5. User submits form again
6. Service checks if WrapperTask is still running, and adds subTask

.

If that's not possible, can I at least show them visually as subtasks of my plugin in the task-list?

**Tags:** plugin-development, tasks
> **Comments:**
> **username_1**: I rolled you over 2k. :-)  
> **username_1**: Suggesting to read about your new [privilege](http://craftcms.stackexchange.com/help/privileges/moderator-tools)  

---

## 1 answers

### Answer by username_2 on 2014-06-26. Score: 7 | Accepted answer

Sub-tasks can only be initiated by the parent task, and they will only visually look like a sub-task if they are actually sub-tasks.

It’s also not possible to change the settings of an already-running task, at least without manually checking for new settings in your task.

So, your parent task’s `getStep()` function would need to do its own checking to see if it should be running a sub-task, somehow, and then conditionally call `$this->runSubTask()`.

> **Comments:**
> **username_0**: Sorry..., I think my question was confusing (note-to-self: never ask questions when tired). I hope it's clearer now, could you take a look again? Thanks a lot. :)  
> **username_2**: Got it. Just updated my answer.  
> **username_0**: Thanks. But is it possible to pass data to a running task? Or would I need to use a Record and check on each run?  
> **username_2**: @VictorIn Updated once again.  

---

