Skip to content

Instantly share code, notes, and snippets.

@ratibus
Created January 6, 2012 08:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ratibus/1569782 to your computer and use it in GitHub Desktop.
Save ratibus/1569782 to your computer and use it in GitHub Desktop.
libnotify within sfTask
I only needed notification in one long running task with multiple sfTasks called inside.
So I added a 'notify' option and put the following code in the beginning of my execute() method :
if ($options['notify'])
{
try
{
$fs = new sfFilesystem();
$fs->execute('which notify-send');
$this->configuration->getEventDispatcher()->connect('command.post_command', array($this, 'listenToCommandPostCommand'));
}
catch(Exception $e)
{
// Pas de notification avec libnotify, pas grave
}
}
And here is my listenToCommandPostCommand method :
/**
* @param sfEvent $event
*/
public function listenToCommandPostCommand(sfEvent $event)
{
try
{
$fs = new sfFilesystem();
$task = $event->getSubject();
$cmd = sprintf("notify-send 'My project' %s", escapeshellarg(sprintf("Task %s finished", $task->getFullName())));
$fs->execute($cmd);
}
catch(Exception $e)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment