Skip to content

Commit 11eb32d

Browse files
authored
Merge pull request #7949 from ProcessMaker/bugfix/FOUR-21497-b
Fix retries and run microservice requests synchronously
2 parents 528c067 + 007e383 commit 11eb32d

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

ProcessMaker/Jobs/ErrorHandling.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Illuminate\Support\Arr;
66
use Illuminate\Support\Facades\Log;
77
use Illuminate\Support\Facades\Notification;
8+
use ProcessMaker\Exception\ScriptException;
9+
use ProcessMaker\Exception\ScriptTimeoutException;
810
use ProcessMaker\Models\Process;
911
use ProcessMaker\Models\ProcessRequest;
1012
use ProcessMaker\Models\ProcessRequestToken;
@@ -204,4 +206,14 @@ public function setDefaultsFromDataSourceConfig(array $config)
204206
'retry_wait_time' => Arr::get($endpointConfig, 'retry_wait_time', 5),
205207
];
206208
}
209+
210+
public static function convertResponseToException($result)
211+
{
212+
if ($result['status'] === 'error') {
213+
if (str_starts_with($result['message'], 'Command exceeded timeout of')) {
214+
throw new ScriptTimeoutException($result['message']);
215+
}
216+
throw new ScriptException($result['message']);
217+
}
218+
}
207219
}

ProcessMaker/Jobs/RunScriptTask.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,9 @@ public function action(ProcessRequestToken $token = null, ScriptTaskInterface $e
108108
'attempts' => $this->attemptNum,
109109
],
110110
];
111-
$response = $script->runScript($data, $configuration, $token->getId(), $errorHandling->timeout(), 0, $metadata);
111+
$response = $script->runScript($data, $configuration, $token->getId(), $errorHandling->timeout(), 1, $metadata);
112112

113-
if (!config('script-runner-microservice.enabled') ||
114-
($scriptExecutor && $scriptExecutor->type === ScriptExecutorType::Custom)) {
115-
$this->updateData($response);
116-
}
113+
$this->updateData($response);
117114
} catch (ConfigurationException $exception) {
118115
$this->unlock();
119116
$this->updateData(['output' => $exception->getMessageForData($token)]);

ProcessMaker/ScriptRunners/ScriptMicroserviceRunner.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use Illuminate\Support\Facades\Http;
88
use Illuminate\Support\Facades\Log;
99
use ProcessMaker\Exception\ConfigurationException;
10-
use ProcessMaker\Exception\ScriptException;
1110
use ProcessMaker\GenerateAccessToken;
11+
use ProcessMaker\Jobs\ErrorHandling;
1212
use ProcessMaker\Models\EnvironmentVariable;
1313
use ProcessMaker\Models\Script;
1414
use ProcessMaker\Models\User;
@@ -95,7 +95,13 @@ public function run($code, array $data, array $config, $timeout, $user, $sync, $
9595

9696
$response->throw();
9797

98-
return $response->json();
98+
$result = $response->json();
99+
100+
if ($sync) {
101+
ErrorHandling::convertResponseToException($result);
102+
}
103+
104+
return $result;
99105
}
100106

101107
private function getEnvironmentVariables(User $user)

ProcessMaker/Traits/TaskControllerIndexMethods.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,13 @@ private function excludeNonVisibleTasks($query, $request)
151151
$nonSystem = filter_var($request->input('non_system'), FILTER_VALIDATE_BOOLEAN);
152152
$allTasks = filter_var($request->input('all_tasks'), FILTER_VALIDATE_BOOLEAN);
153153
$query->when(!$allTasks, function ($query) {
154-
$query->where('element_type', '=', 'task');
155-
$query->orWhere('element_type', '=', 'serviceTask');
156-
$query->where('element_name', '=', 'AI Assistant');
154+
$query->where(function ($query) {
155+
$query->where('element_type', '=', 'task');
156+
$query->orWhere(function ($query) {
157+
$query->where('element_type', '=', 'serviceTask');
158+
$query->where('element_name', '=', 'AI Assistant');
159+
});
160+
});
157161
})
158162
->when($nonSystem, function ($query) {
159163
$query->nonSystem();

0 commit comments

Comments
 (0)