<p>The simple way to do this would be to log a message to your Plugin's custom log using</p>

<p><code>ExamplePlugin::log( 'TaskName has completed' );</code></p>

<p>This would require the user to visit the log and refresh to see if the task had completed - not ideal!</p>

<p>However, if you wanted something that updated as the task was being run you could possibly redirect them to a Plugin template with a text area that  displays a log for the task where you could show completion of each step of the task and then finally a "Completed Task" message.</p>

<pre><code>// Create task
$task = craft()-&gt;tasks-&gt;createTask( 'TaskName', 'desc' ), array(
  'products' =&gt; $products
));

// Set session notice for start
craft()-&gt;userSession-&gt;setNotice(Craft::t('Import process started.'));

// Redirect to Plugin template page that displays a log
$this-&gt;redirect( 'templateName?task=' . $task-&gt;id );
</code></pre>

<p>Then inside the task you could log messages to be displayed in that template</p>

<pre><code>if($step === $this-&gt;getTotalSteps()-1) {
  Log::message( 'Task finished.' );
}
</code></pre>

CC BY-SA 3.0
2016-05-26T08:45:22.220Z
Thanks Pearce for this insight, maybe in combination what this guy is pointing to http://craftcms.stackexchange.com/questions/10158/detect-task-is-finished/10168#10168 it is possible to show this in the current view. For now I will stick with the log options for a first version release.
Jacob
CC BY-SA 3.0
2016-05-25T10:06:31.600Z
2016-05-25T10:11:50.593Z
2016-05-25T10:11:50.593Z
Luke Pearce
<p>Is it possible to somehow notify the user from a completing task?
I am walking trough a set of .csv files and on completion i would like to notify the user.</p>

<pre><code>// last step
$stepIndex = $step + 1;
if ( $stepIndex == $this-&gt;getTotalSteps() )
{
    craft()-&gt;userSession-&gt;getFlash('notice', 'Reroutes  imported.');
    // craft()-&gt;userSession-&gt;setNotice(Craft::t('Reroutes   imported.'));
    // craft()-&gt;userSession-&gt;getFlashes();
}

return true;
</code></pre>

<p>I tried with the <code>UserSessionService</code> but i guess that won't work because the task is running separately from the session. If so reloading the page would be a good alternative but how can I let the front-end know of the task being completed.</p>

<plugin-development><control-panel><tasks><plugin-pushnotifications>
How to notify the user from a Task
# How to notify the user from a Task

(Asked by: username_0 on 2016-05-25)

Is it possible to somehow notify the user from a completing task?
I am walking trough a set of .csv files and on completion i would like to notify the user.
// last step
$stepIndex = $step + 1;
if ( $stepIndex == $this->getTotalSteps() )
{
    craft()->userSession->getFlash('notice', 'Reroutes  imported.');
    // craft()->userSession->setNotice(Craft::t('Reroutes   imported.'));
    // craft()->userSession->getFlashes();
}

return true;

I tried with the UserSessionService but i guess that won't work because the task is running separately from the session. If so reloading the page would be a good alternative but how can I let the front-end know of the task being completed.

**Tags:** plugin-development, control-panel, tasks, plugin-pushnotifications

---

## 1 answers

### Answer by username_1 on 2016-05-25. Score: 3 | Accepted answer

The simple way to do this would be to log a message to your Plugin's custom log using
ExamplePlugin::log( 'TaskName has completed' );
This would require the user to visit the log and refresh to see if the task had completed - not ideal!
However, if you wanted something that updated as the task was being run you could possibly redirect them to a Plugin template with a text area that  displays a log for the task where you could show completion of each step of the task and then finally a "Completed Task" message.
// Create task
$task = craft()->tasks->createTask( 'TaskName', 'desc' ), array(
  'products' => $products
));

// Set session notice for start
craft()->userSession->setNotice(Craft::t('Import process started.'));

// Redirect to Plugin template page that displays a log
$this->redirect( 'templateName?task=' . $task->id );

Then inside the task you could log messages to be displayed in that template
if($step === $this->getTotalSteps()-1) {
  Log::message( 'Task finished.' );
}

> **Comments:**
> **username_0**: Thanks Pearce for this insight, maybe in combination what this guy is pointing to http://craftcms.stackexchange.com/questions/10158/detect-task-is-finished/10168#10168 it is possible to show this in the current view. For now I will stick with the log options for a first version release.  

---

