1+ <?php
2+ // Somewhere in our application, we need to register:
3+ Resque_Event::listen ('afterEnqueue ' , array ('My_Resque_Plugin ' , 'afterEnqueue ' ));
4+ Resque_Event::listen ('beforeFirstFork ' , array ('My_Resque_Plugin ' , 'beforeFirstFork ' ));
5+ Resque_Event::listen ('beforeFork ' , array ('My_Resque_Plugin ' , 'beforeFork ' ));
6+ Resque_Event::listen ('afterFork ' , array ('My_Resque_Plugin ' , 'afterFork ' ));
7+ Resque_Event::listen ('beforePerform ' , array ('My_Resque_Plugin ' , 'beforePerform ' ));
8+ Resque_Event::listen ('afterPerform ' , array ('My_Resque_Plugin ' , 'afterPerform ' ));
9+ Resque_Event::listen ('onFailure ' , array ('My_Resque_Plugin ' , 'onFailure ' ));
10+
11+ class My_Resque_Plugin
12+ {
13+ public static function afterEnqueue ($ class , $ arguments )
14+ {
15+ echo "Job was queued for " . $ class . ". Arguments: " ;
16+ print_r ($ arguments );
17+ }
18+
19+ public static function beforeFirstFork ($ worker )
20+ {
21+ echo "Worker started. Listening on queues: " . implode (', ' , $ worker ->queues (false )) . "\n" ;
22+ }
23+
24+ public static function beforeFork ($ job )
25+ {
26+ echo "Just about to fork to run " . $ job ;
27+ }
28+
29+ public static function afterFork ($ job )
30+ {
31+ echo "Forked to run " . $ job . ". This is the child process. \n" ;
32+ }
33+
34+ public static function beforePerform ($ job )
35+ {
36+ echo "Cancelling " . $ job . "\n" ;
37+ // throw new Resque_Job_DontPerform;
38+ }
39+
40+ public static function afterPerform ($ job )
41+ {
42+ echo "Just performed " . $ job . "\n" ;
43+ }
44+
45+ public static function onFailure ($ exception , $ job )
46+ {
47+ echo $ job . " threw an exception: \n" . $ exception ;
48+ }
49+ }
0 commit comments