Skip to content

Fix retries and run microservice requests synchronously #7949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ProcessMaker/Jobs/ErrorHandling.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
use ProcessMaker\Exception\ScriptException;
use ProcessMaker\Exception\ScriptTimeoutException;
use ProcessMaker\Models\Process;
use ProcessMaker\Models\ProcessRequest;
use ProcessMaker\Models\ProcessRequestToken;
Expand Down Expand Up @@ -204,4 +206,14 @@ public function setDefaultsFromDataSourceConfig(array $config)
'retry_wait_time' => Arr::get($endpointConfig, 'retry_wait_time', 5),
];
}

public static function convertResponseToException($result)
{
if ($result['status'] === 'error') {
if (str_starts_with($result['message'], 'Command exceeded timeout of')) {
throw new ScriptTimeoutException($result['message']);
}
throw new ScriptException($result['message']);
}
}
}
7 changes: 2 additions & 5 deletions ProcessMaker/Jobs/RunScriptTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,9 @@ public function action(ProcessRequestToken $token = null, ScriptTaskInterface $e
'attempts' => $this->attemptNum,
],
];
$response = $script->runScript($data, $configuration, $token->getId(), $errorHandling->timeout(), 0, $metadata);
$response = $script->runScript($data, $configuration, $token->getId(), $errorHandling->timeout(), 1, $metadata);

if (!config('script-runner-microservice.enabled') ||
($scriptExecutor && $scriptExecutor->type === ScriptExecutorType::Custom)) {
$this->updateData($response);
}
$this->updateData($response);
} catch (ConfigurationException $exception) {
$this->unlock();
$this->updateData(['output' => $exception->getMessageForData($token)]);
Expand Down
10 changes: 8 additions & 2 deletions ProcessMaker/ScriptRunners/ScriptMicroserviceRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use ProcessMaker\Exception\ConfigurationException;
use ProcessMaker\Exception\ScriptException;
use ProcessMaker\GenerateAccessToken;
use ProcessMaker\Jobs\ErrorHandling;
use ProcessMaker\Models\EnvironmentVariable;
use ProcessMaker\Models\Script;
use ProcessMaker\Models\User;
Expand Down Expand Up @@ -95,7 +95,13 @@ public function run($code, array $data, array $config, $timeout, $user, $sync, $

$response->throw();

return $response->json();
$result = $response->json();

if ($sync) {
ErrorHandling::convertResponseToException($result);
}

return $result;
}

private function getEnvironmentVariables(User $user)
Expand Down
10 changes: 7 additions & 3 deletions ProcessMaker/Traits/TaskControllerIndexMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,13 @@ private function excludeNonVisibleTasks($query, $request)
$nonSystem = filter_var($request->input('non_system'), FILTER_VALIDATE_BOOLEAN);
$allTasks = filter_var($request->input('all_tasks'), FILTER_VALIDATE_BOOLEAN);
$query->when(!$allTasks, function ($query) {
$query->where('element_type', '=', 'task');
$query->orWhere('element_type', '=', 'serviceTask');
$query->where('element_name', '=', 'AI Assistant');
$query->where(function ($query) {
$query->where('element_type', '=', 'task');
$query->orWhere(function ($query) {
$query->where('element_type', '=', 'serviceTask');
$query->where('element_name', '=', 'AI Assistant');
});
});
})
->when($nonSystem, function ($query) {
$query->nonSystem();
Expand Down
Loading