@@ -48,7 +48,27 @@ public static function collectJobs() {
4848 */
4949 public static function getStatus (AbstractJob $ job ) {
5050 $ jobId = $ job ->getId ();
51- return self ::getPersistedStatus ($ jobId );
51+ $ currentStatus = self ::getPersistedStatus ($ jobId );
52+ if ($ currentStatus ->isLocked && !\Foomo \Lock::isLocked ($ jobId )) {
53+ // that is a locking lie
54+ \Foomo \Lock::lock ($ jobId , true );
55+ $ persisted = self ::getPersistedStatus ($ jobId );
56+ if ($ persisted ->isLocked ) {
57+ // that is bullshit - we got the lock - sbdy died
58+ self ::updateStatusJobError (
59+ $ jobId ,
60+ $ persisted ->pid ,
61+ JobStatus::ERROR_DIED ,
62+ "sbdy died alone " ,
63+ false ,
64+ false
65+ );
66+ }
67+ \Foomo \Lock::release ($ job ->getId ());
68+ return self ::getPersistedStatus ($ jobId );
69+ } else {
70+ return $ currentStatus ;
71+ }
5272 }
5373
5474 public static function getExecutionSecret () {
@@ -145,7 +165,8 @@ public static function updateStatusJobDone($jobId, $pid) {
145165 * @param string $isRunning one of self::STATUS_
146166 * @param boolean $isLocked
147167 */
148- public static function updateStatusJobError ($ jobId , $ pid , $ errorCode , $ errorMessage , $ isRunning = false , $ isLocked = false ) {
168+ public static function updateStatusJobError ($ jobId , $ pid , $ errorCode , $ errorMessage , $ isRunning = false , $ isLocked = false )
169+ {
149170 $ status = self ::getPersistedStatus ($ jobId );
150171 $ fileName = self ::getJobStatusFile ($ jobId );
151172 $ status ->status = $ isRunning ? JobStatus::STATUS_RUNNING : JobStatus::STATUS_NOT_RUNNING ;
@@ -158,19 +179,19 @@ public static function updateStatusJobError($jobId, $pid, $errorCode, $errorMess
158179 self ::log ($ jobId , $ status );
159180 self ::persistStatus ($ fileName , $ status );
160181 self ::sendNotificationEmail ($ status ->errorCode , $ status ->errorMessage );
161-
162-
163-
164182 }
165183
166- private static function getPersistedStatus ($ jobId ) {
184+ private static function getPersistedStatus ($ jobId )
185+ {
167186 $ fileName = self ::getJobStatusFile ($ jobId );
187+ $ status = new JobStatus ();
168188 if (file_exists ($ fileName )) {
169- $ contents = unserialize (file_get_contents ($ fileName ));
170- } else {
171- $ contents = new JobStatus ();
189+ $ unserialized = unserialize (file_get_contents ($ fileName ));
190+ if (is_object ($ unserialized ) && $ unserialized instanceof JobStatus) {
191+ $ status = $ unserialized ;
192+ }
172193 }
173- return $ contents ;
194+ return $ status ;
174195 }
175196
176197 private static function getJobStatusFile ($ jobId ) {
0 commit comments