From 1f8d543bcb81bc2e60843f2156e117c2f420fe3b Mon Sep 17 00:00:00 2001
From: Tristan Cavelier <tristan.cavelier@tiolive.com>
Date: Thu, 22 Aug 2013 16:00:29 +0200
Subject: [PATCH] JIO job management does not recover waiting jobs -> fixed

---
 src/jio/features/jobRecovery.js | 3 ++-
 src/jio/features/jobRetry.js    | 2 +-
 test/jio/tests.js               | 8 ++++----
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/jio/features/jobRecovery.js b/src/jio/features/jobRecovery.js
index dff3298..1d42588 100644
--- a/src/jio/features/jobRecovery.js
+++ b/src/jio/features/jobRecovery.js
@@ -46,7 +46,8 @@ function enableJobRecovery(jio, shared, options) {
 
     for (i = 0; i < job_array.length; i += 1) {
       if (job_array[i].state === 'ready' ||
-          job_array[i].state === 'running') {
+          job_array[i].state === 'running' ||
+          job_array[i].state === 'waiting') {
         delay = numberOrDefault(job_array[i].timeout + recovery_delay,
                                 recovery_delay);
         deadline = new Date(job_array[i].modified).getTime() + delay;
diff --git a/src/jio/features/jobRetry.js b/src/jio/features/jobRetry.js
index 7f5c305..9ceca69 100644
--- a/src/jio/features/jobRetry.js
+++ b/src/jio/features/jobRetry.js
@@ -70,7 +70,7 @@ function enableJobRetry(jio, shared, options) {
           param.max_retry > param.tried) {
         param.state = 'waiting';
         param.modified = new Date();
-        shared.emit('jobStateChange', param);
+        shared.emit('jobStop', param);
         setTimeout(function () {
           param.state = 'ready';
           param.modified = new Date();
diff --git a/test/jio/tests.js b/test/jio/tests.js
index 2e6ef79..72168f9 100644
--- a/test/jio/tests.js
+++ b/test/jio/tests.js
@@ -843,21 +843,21 @@
       "workspace": workspace
     });
 
-    clock.tick(17998); // now: 19999 ms
+    clock.tick(17999); // now: 20000 ms
     if (fakestorage['Job Recove/post']) {
       ok(false, "Command called, job recovered to earlier");
     }
-    clock.tick(1); // now: 20000 ms
+    clock.tick(1); // now: 20001 ms
     if (!fakestorage['Job Recove/post']) {
       ok(false, "Command not called, job recovery failed");
     } else {
       ok(true, "Command called, job recovery ok");
     }
     fakestorage['Job Recove/post'].success({"id": "a"});
-    clock.tick(1); // now: 20001 ms
+    clock.tick(1); // now: 20002 ms
 
     deepEqual(workspace, {}, 'No more job in the queue');
-    clock.tick(79999); // now: 100000 ms
+    clock.tick(79998); // now: 100000 ms
 
     //////////////////////////////
     // XXX Waiting for jobs job recovery
-- 
2.30.9