Skip to content

Commit 950026d

Browse files
committed
FOUR-8993 Use the queue for retries instead of sleeping and retrying in the same job
1 parent 60f7274 commit 950026d

3 files changed

Lines changed: 41 additions & 6 deletions

File tree

‎ProcessMaker/Jobs/ClosureJob.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace ProcessMaker\Jobs;
4+
5+
class ClosureJob extends ClosureJobInterface //ShouldQueue
6+
{
7+
8+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace ProcessMaker\Jobs;
4+
5+
use Closure;
6+
use Illuminate\Queue\CallQueuedClosure;
7+
use Illuminate\Queue\SerializableClosure;
8+
9+
abstract class ClosureJobInterface extends CallQueuedClosure
10+
{
11+
12+
/**
13+
* Create a new job instance.
14+
*
15+
* @param \Illuminate\Queue\SerializableClosure $closure
16+
*/
17+
public function __construct(Closure $closure)
18+
{
19+
parent::__construct(new SerializableClosure($closure));
20+
}
21+
}

‎ProcessMaker/Models/Script.php‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
use Illuminate\Support\Arr;
77
use Illuminate\Support\Facades\Log;
88
use Illuminate\Support\Facades\Notification;
9+
use Illuminate\Support\Facades\Queue;
910
use Illuminate\Validation\Rule;
1011
use ProcessMaker\Contracts\ScriptInterface;
1112
use ProcessMaker\Exception\ScriptException;
1213
use ProcessMaker\Exception\ScriptLanguageNotSupported;
1314
use ProcessMaker\Exception\ScriptTimeoutException;
1415
use ProcessMaker\GenerateAccessToken;
16+
use ProcessMaker\Jobs\ClosureJob;
1517
use ProcessMaker\Models\ScriptCategory;
1618
use ProcessMaker\Models\User;
1719
use ProcessMaker\Notifications\ErrorExecutionNotification;
@@ -172,15 +174,19 @@ public function runScript(array $data, array $config, $tokenId = '', $errorHandl
172174
throw new ScriptException($message);
173175
}
174176

175-
Log::info("Waiting {$this->retryWaitTime()} seconds before retrying.");
176-
sleep($this->retryWaitTime());
177+
$closure = function () use ($data, $config, $tokenId, $errorHandling) {
178+
Log::info('Re-running the script');
179+
$this->runScript($data, $config, $tokenId, $errorHandling);//todo: it is important to return the correct data.
180+
Log::info('The script completed successfully');
181+
};
182+
183+
$retryWaitTime = $this->retryWaitTime();
184+
Log::info("Waiting {$retryWaitTime} seconds before retrying.");
177185
$this->attemptedRetries++;
178186

179-
Log::info('Re-running the script');
180-
$result = $this->runScript($data, $config, $tokenId, $errorHandling);
181-
Log::info('The script completed successfully');
187+
Queue::later($retryWaitTime, new ClosureJob($closure));
182188

183-
return $result;
189+
return ['output'];//todo: it is important to return the correct data.
184190
} else {
185191
$this->sendExecutionErrorNotification($e->getMessage(), $tokenId, $errorHandling);
186192
throw $e;

0 commit comments

Comments
 (0)