-
Notifications
You must be signed in to change notification settings - Fork 248
FOUR-28073 Canceled case still progresses to Completed #8801
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| use ProcessMaker\Exception\ScriptException; | ||
| use ProcessMaker\Facades\WorkflowManager; | ||
| use ProcessMaker\Managers\DataManager; | ||
| use ProcessMaker\Models\ProcessRequest; | ||
| use ProcessMaker\Models\ProcessRequestToken; | ||
| use ProcessMaker\Models\Script; | ||
| use ProcessMaker\Models\ScriptExecutor; | ||
|
|
@@ -36,7 +37,7 @@ class RunNayraScriptTask implements ShouldQueue | |
| /** | ||
| * Create a new job instance. | ||
| * | ||
| * @param \ProcessMaker\Models\ProcessRequestToken $token | ||
| * @param ProcessRequestToken $token | ||
| * @param array $data | ||
| */ | ||
| public function __construct(TokenInterface $token) | ||
|
|
@@ -99,10 +100,27 @@ public function handle() | |
|
|
||
| $response = $script->runScript($data, $configuration, $token->getId(), $errorHandling->timeout()); | ||
|
|
||
| if (ProcessRequest::query()->whereKey($instance->getKey())->value('status') === 'CANCELED') { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gproly Not sure if this is needed, because completeTask verifies that the token is ACTIVE. Could you try to remove this code? |
||
| Log::info('Skipping script task completion because the request was canceled.', [ | ||
| 'process_request_id' => $instance->getKey(), | ||
| 'token_id' => $token->getKey(), | ||
| ]); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| // Dispatch complete task action | ||
| WorkflowManager::completeTask($processModel, $instance, $token, $response['output']); | ||
| } catch (ConfigurationException $exception) { | ||
| $output = $exception->getMessageForData($token); | ||
| if (ProcessRequest::query()->whereKey($instance->getKey())->value('status') === 'CANCELED') { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gproly Not sure if this is needed, because completeTask verifies that the token is ACTIVE. Could you try to remove this code? |
||
| Log::info('Skipping script task completion because the request was canceled.', [ | ||
| 'process_request_id' => $instance->getKey(), | ||
| 'token_id' => $token->getKey(), | ||
| ]); | ||
|
|
||
| return; | ||
| } | ||
| WorkflowManager::completeTask($processModel, $instance, $token, $output); | ||
| } catch (Throwable $exception) { | ||
| Log::error('Script failed: ' . $scriptRef . ' - ' . $exception->getMessage()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| namespace ProcessMaker\Nayra\Managers; | ||
|
|
||
| use Illuminate\Http\Exceptions\HttpResponseException; | ||
| use Illuminate\Support\Arr; | ||
| use Illuminate\Support\Facades\Log; | ||
| use Illuminate\Support\Facades\Validator; | ||
|
|
@@ -71,6 +72,14 @@ public function completeTask(Definitions $definitions, ExecutionInstanceInterfac | |
| //Validate data | ||
| $element = $token->getDefinition(true); | ||
| $this->validateData($data, $definitions, $element); | ||
| if ($instance instanceof ProcessRequest) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gproly Not sure if this is needed, because CompleteActivity should verify that the token is ACTIVE. Could you check if this verification could go to the Job? |
||
| $status = ProcessRequest::query()->whereKey($instance->getKey())->value('status'); | ||
| if ($status === 'CANCELED') { | ||
| throw new HttpResponseException(response()->json([ | ||
| 'message' => __('This request has been canceled. The task cannot be completed.'), | ||
| ], 422)); | ||
| } | ||
| } | ||
| CompleteActivity::dispatchSync($definitions, $instance, $token, $data); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gproly Why this change is needed?