@@ -116,35 +116,40 @@ public function add() {
116
116
public function runworker () {
117
117
$ exit = false ;
118
118
$ starttime = time ();
119
+
119
120
while (!$ exit ) {
120
121
$ this ->out ('Looking for Job.... ' );
121
122
$ data = $ this ->QueuedTask ->requestJob ($ this ->getTaskConf ());
122
- if ($ data != false ) {
123
- $ this ->out ('Running Job of type " ' . $ data ['jobtype ' ] . '" ' );
124
- $ taskname = 'queue_ ' . strtolower ($ data ['jobtype ' ]);
125
- $ return = $ this ->{$ taskname }->run (unserialize ($ data ['data ' ]));
126
- if ($ return == true ) {
127
- $ this ->QueuedTask ->markJobDone ($ data ['id ' ]);
128
- $ this ->out ('Job Finished. ' );
123
+ if ($ this ->QueuedTask ->exit === true ) {
124
+ $ exit = true ;
125
+ } else {
126
+ if ($ data !== false ) {
127
+ $ this ->out ('Running Job of type " ' . $ data ['jobtype ' ] . '" ' );
128
+ $ taskname = 'queue_ ' . strtolower ($ data ['jobtype ' ]);
129
+ $ return = $ this ->{$ taskname }->run (unserialize ($ data ['data ' ]));
130
+ if ($ return == true ) {
131
+ $ this ->QueuedTask ->markJobDone ($ data ['id ' ]);
132
+ $ this ->out ('Job Finished. ' );
133
+ } else {
134
+ $ this ->QueuedTask ->markJobFailed ($ data ['id ' ]);
135
+ $ this ->out ('Job did not finish, requeued. ' );
136
+ }
129
137
} else {
130
- $ this ->QueuedTask -> markJobFailed ( $ data [ ' id ' ] );
131
- $ this -> out ( ' Job did not finish, requeued. ' );
138
+ $ this ->out ( ' nothing to do, sleeping. ' );
139
+ sleep (Configure:: read ( ' queue.sleeptime ' ) );
132
140
}
133
- } else {
134
- $ this ->out ('nothing to do, sleeping. ' );
135
- sleep (Configure::read ('queue.sleeptime ' ));
136
- }
137
141
138
- // check if we are over the maximum runtime and end processing if so.
139
- if (Configure::read ('queue.workermaxruntime ' ) != 0 && (time () - $ starttime ) >= Configure::read ('queue.workermaxruntime ' )) {
140
- $ exit = true ;
141
- $ this ->out ('Reached runtime of ' . (time () - $ starttime ) . ' Seconds (Max ' . Configure::read ('queue.workermaxruntime ' ) . '), terminating. ' );
142
- }
143
- if ($ exit || rand (0 , 100 ) > (100 - Configure::read ('queue.gcprop ' ))) {
144
- $ this ->out ('Performing Old job cleanup. ' );
145
- $ this ->QueuedTask ->cleanOldJobs ();
142
+ // check if we are over the maximum runtime and end processing if so.
143
+ if (Configure::read ('queue.workermaxruntime ' ) != 0 && (time () - $ starttime ) >= Configure::read ('queue.workermaxruntime ' )) {
144
+ $ exit = true ;
145
+ $ this ->out ('Reached runtime of ' . (time () - $ starttime ) . ' Seconds (Max ' . Configure::read ('queue.workermaxruntime ' ) . '), terminating. ' );
146
+ }
147
+ if ($ exit || rand (0 , 100 ) > (100 - Configure::read ('queue.gcprop ' ))) {
148
+ $ this ->out ('Performing Old job cleanup. ' );
149
+ $ this ->QueuedTask ->cleanOldJobs ();
150
+ }
151
+ $ this ->hr ();
146
152
}
147
- $ this ->hr ();
148
153
}
149
154
}
150
155
0 commit comments