Created
January 6, 2012 08:57
-
-
Save ratibus/1569782 to your computer and use it in GitHub Desktop.
libnotify within sfTask
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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