-
Notifications
You must be signed in to change notification settings - Fork 242
FOUR-28426: Add custom executor in microservices feature #8651
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 |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| use ProcessMaker\Jobs\BuildScriptExecutor; | ||
| use ProcessMaker\Models\Script; | ||
| use ProcessMaker\Models\ScriptExecutor; | ||
| use ProcessMaker\Services\ScriptMicroserviceService; | ||
|
|
||
| class ScriptExecutorController extends Controller | ||
| { | ||
|
|
@@ -26,7 +27,7 @@ class ScriptExecutorController extends Controller | |
| * @return ResponseFactory|Response | ||
| * | ||
| * | ||
| * @OA\Get( | ||
| * @OA\Get( | ||
| * path="/script-executors", | ||
| * summary="Returns all script executors that the user has access to", | ||
| * operationId="getScriptExecutors", | ||
|
|
@@ -79,7 +80,7 @@ public function index(Request $request) | |
| * @return ResponseFactory|Response | ||
| * | ||
| * | ||
| * @OA\Post( | ||
| * @OA\Post( | ||
| * path="/script-executors", | ||
| * summary="Create a script executor", | ||
| * operationId="createScriptExecutor", | ||
|
|
@@ -109,7 +110,7 @@ public function index(Request $request) | |
| * ), | ||
| * ) | ||
| */ | ||
| public function store(Request $request) | ||
| public function store(Request $request, ScriptMicroserviceService $service) | ||
| { | ||
| $request->request->add(['type' => 'custom']); | ||
| $this->checkAuth($request); | ||
|
|
@@ -119,11 +120,14 @@ public function store(Request $request) | |
| $request->only((new ScriptExecutor())->getFillable()) | ||
| ); | ||
|
|
||
| ScriptExecutorCreated::dispatch($scriptExecutor->getAttributes()); | ||
|
|
||
| BuildScriptExecutor::dispatch($scriptExecutor->id, $request->user()->id); | ||
| if (!config('script-runner-microservice.enabled')) { | ||
| ScriptExecutorCreated::dispatch($scriptExecutor->getAttributes()); | ||
| BuildScriptExecutor::dispatch($scriptExecutor->id, $request->user()->id); | ||
| } else { | ||
| $service->createCustomExecutor($scriptExecutor); | ||
| } | ||
|
|
||
| return ['status'=>'started', 'id' => $scriptExecutor->id]; | ||
| return ['status' => 'started', 'id' => $scriptExecutor->id]; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -135,7 +139,7 @@ public function store(Request $request) | |
| * @return ResponseFactory|Response | ||
| * | ||
| * | ||
| * @OA\Put( | ||
| * @OA\Put( | ||
| * path="/script-executors/{script_executor}", | ||
| * summary="Update script executor", | ||
| * operationId="updateScriptExecutor", | ||
|
|
@@ -173,7 +177,7 @@ public function store(Request $request) | |
| * ) | ||
| * ) | ||
| */ | ||
| public function update(Request $request, ScriptExecutor $scriptExecutor) | ||
| public function update(Request $request, ScriptExecutor $scriptExecutor, ScriptMicroserviceService $service) | ||
| { | ||
| $this->checkAuth($request); | ||
| $request->validate(ScriptExecutor::rules()); | ||
|
|
@@ -184,13 +188,16 @@ public function update(Request $request, ScriptExecutor $scriptExecutor) | |
| $request->only($scriptExecutor->getFillable()) | ||
| ); | ||
|
|
||
| if (!empty($scriptExecutor->getChanges())) { | ||
| ScriptExecutorUpdated::dispatch($scriptExecutor->id, $original, $scriptExecutor->getChanges()); | ||
| if (!config('script-runner-microservice.enabled')) { | ||
| if (!empty($scriptExecutor->getChanges())) { | ||
| ScriptExecutorUpdated::dispatch($scriptExecutor->id, $original, $scriptExecutor->getChanges()); | ||
| } | ||
| BuildScriptExecutor::dispatch($scriptExecutor->id, $request->user()->id); | ||
| } else { | ||
| $service->updateCustomExecutor($scriptExecutor); | ||
| } | ||
|
|
||
| BuildScriptExecutor::dispatch($scriptExecutor->id, $request->user()->id); | ||
|
|
||
| return ['status'=>'started']; | ||
| return ['status' => 'started']; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -202,7 +209,7 @@ public function update(Request $request, ScriptExecutor $scriptExecutor) | |
| * @return ResponseFactory|Response | ||
| * | ||
| * | ||
| * @OA\Delete( | ||
| * @OA\Delete( | ||
| * path="/script-executors/{script_executor}", | ||
| * summary="Delete a script executor", | ||
| * operationId="deleteScriptExecutor", | ||
|
|
@@ -233,7 +240,7 @@ public function update(Request $request, ScriptExecutor $scriptExecutor) | |
| * ), | ||
| * ) | ||
| */ | ||
| public function delete(Request $request, ScriptExecutor $scriptExecutor) | ||
| public function delete(Request $request, ScriptExecutor $scriptExecutor, ScriptMicroserviceService $service) | ||
| { | ||
| if ($scriptExecutor->scripts()->count() > 0) { | ||
| throw ValidationException::withMessages(['delete' => __('Can not delete executor when it is assigned to scripts.')]); | ||
|
|
@@ -254,9 +261,15 @@ public function delete(Request $request, ScriptExecutor $scriptExecutor) | |
| } | ||
| } | ||
|
|
||
| $scriptExecutorUUID = $scriptExecutor->uuid; | ||
|
|
||
| ScriptExecutor::destroy($scriptExecutor->id); | ||
|
|
||
| ScriptExecutorDeleted::dispatch($scriptExecutor->getAttributes()); | ||
| if (!config('script-runner-microservice.enabled')) { | ||
| ScriptExecutorDeleted::dispatch($scriptExecutor->getAttributes()); | ||
| } else { | ||
| $service->deleteCustomExecutor($scriptExecutorUUID); | ||
| } | ||
|
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. Delete order causes inconsistency if microservice call failsThe |
||
|
|
||
| return ['status' => 'done']; | ||
| } | ||
|
|
@@ -280,7 +293,7 @@ private function checkAuth($request) | |
| * @return ResponseFactory|Response | ||
| * | ||
| * | ||
| * @OA\Post( | ||
| * @OA\Post( | ||
| * path="/script-executors/cancel", | ||
| * summary="Cancel a script executor", | ||
| * operationId="cancelScriptExecutor", | ||
|
|
@@ -327,7 +340,7 @@ public function cancel(Request $request) | |
| * @return ResponseFactory|Response | ||
| * | ||
| * | ||
| * @OA\Get( | ||
| * @OA\Get( | ||
| * path="/script-executors/available-languages", | ||
| * summary="Returns all available languages", | ||
| * operationId="getAvailableLanguages", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.