From 1deddc05d088b7e92fa6b814d5f4050beb84ceba Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Fri, 19 Jul 2019 09:56:20 -0400 Subject: [PATCH] PMC-964 We need a new artisan command to manage the failed jobs, because we need to load the workspace configuration --- app/Console/Commands/AddParametersTrait.php | 42 ++++++++++++++++++++ app/Console/Commands/FailedTableCommand.php | 39 ++++++++++++++++++ app/Console/Commands/FlushFailedCommand.php | 20 ++++++++++ app/Console/Commands/ForgetFailedCommand.php | 14 +++++++ app/Console/Commands/ListFailedCommand.php | 20 ++++++++++ app/Console/Commands/RestartCommand.php | 20 ++++++++++ app/Console/Commands/RetryCommand.php | 14 +++++++ app/Console/Commands/TableCommand.php | 39 ++++++++++++++++++ app/Console/Commands/WorkCommand.php | 32 +-------------- config/queue.php | 2 +- workflow/engine/bin/tasks/cliWorkspaces.php | 16 ++++---- 11 files changed, 218 insertions(+), 40 deletions(-) create mode 100644 app/Console/Commands/AddParametersTrait.php create mode 100644 app/Console/Commands/FailedTableCommand.php create mode 100644 app/Console/Commands/FlushFailedCommand.php create mode 100644 app/Console/Commands/ForgetFailedCommand.php create mode 100644 app/Console/Commands/ListFailedCommand.php create mode 100644 app/Console/Commands/RestartCommand.php create mode 100644 app/Console/Commands/RetryCommand.php create mode 100644 app/Console/Commands/TableCommand.php diff --git a/app/Console/Commands/AddParametersTrait.php b/app/Console/Commands/AddParametersTrait.php new file mode 100644 index 000000000..b1bcb5bbb --- /dev/null +++ b/app/Console/Commands/AddParametersTrait.php @@ -0,0 +1,42 @@ +signature .= ' + {--workspace=workflow : ProcessMaker Indicates the workspace to be processed.} + {--processmakerPath=./ : ProcessMaker path.} + '; + + $this->description .= ' (ProcessMaker has extended this command)'; + + parent::__construct(); + } + + /** + * Execute the console command. + * + * @return void + */ + public function handle() + { + $workspace = $this->option('workspace'); + if (!empty($workspace)) { + $webApplication = new WebApplication(); + $webApplication->setRootDir($this->option('processmakerPath')); + $webApplication->loadEnvironment($workspace); + } + parent::handle(); + } +} diff --git a/app/Console/Commands/FailedTableCommand.php b/app/Console/Commands/FailedTableCommand.php new file mode 100644 index 000000000..1bbcadbc6 --- /dev/null +++ b/app/Console/Commands/FailedTableCommand.php @@ -0,0 +1,39 @@ +signature .= ' + {--workspace=workflow : ProcessMaker Indicates the workspace to be processed.} + {--processmakerPath=./ : ProcessMaker path.} + '; + + $this->description .= ' (ProcessMaker has extended this command)'; + + parent::__construct($files, $composer); + } +} diff --git a/app/Console/Commands/FlushFailedCommand.php b/app/Console/Commands/FlushFailedCommand.php new file mode 100644 index 000000000..f623deaeb --- /dev/null +++ b/app/Console/Commands/FlushFailedCommand.php @@ -0,0 +1,20 @@ +signature .= ' + {--workspace=workflow : ProcessMaker Indicates the workspace to be processed.} + {--processmakerPath=./ : ProcessMaker path.} + '; + + $this->description .= ' (ProcessMaker has extended this command)'; + + parent::__construct($files, $composer); + } +} diff --git a/app/Console/Commands/WorkCommand.php b/app/Console/Commands/WorkCommand.php index 708e8c114..f27ecd086 100644 --- a/app/Console/Commands/WorkCommand.php +++ b/app/Console/Commands/WorkCommand.php @@ -4,11 +4,12 @@ namespace App\Console\Commands; use Illuminate\Queue\Console\WorkCommand as BaseWorkCommand; use Illuminate\Queue\Worker; -use Maveriks\WebApplication; class WorkCommand extends BaseWorkCommand { + use AddParametersTrait; + /** * Create a new queue work command. * @@ -27,33 +28,4 @@ class WorkCommand extends BaseWorkCommand parent::__construct($worker); } - - /** - * Run the worker instance. - * - * @param string $connection - * @param string $queue - */ - protected function runWorker($connection, $queue) - { - $workspace = $this->option('workspace'); - - if (!empty($workspace)) { - $webApplication = new WebApplication(); - $webApplication->setRootDir($this->option('processmakerPath')); - $webApplication->loadEnvironment($workspace); - } - parent::runWorker($connection, $queue); - } - - /** - * Gather all of the queue worker options as a single object. - * - * @return \Illuminate\Queue\WorkerOptions - */ - protected function gatherWorkerOptions() - { - $options = parent::gatherWorkerOptions(); - return $options; - } } diff --git a/config/queue.php b/config/queue.php index a59550e0b..ea317483a 100644 --- a/config/queue.php +++ b/config/queue.php @@ -80,7 +80,7 @@ return [ */ 'failed' => [ - 'database' => env('DB_CONNECTION', 'mysql'), + 'database' => env('DB_CONNECTION', 'workflow'), 'table' => 'JOBS_FAILED', ], diff --git a/workflow/engine/bin/tasks/cliWorkspaces.php b/workflow/engine/bin/tasks/cliWorkspaces.php index 0e9f3a5a6..73eb38eea 100644 --- a/workflow/engine/bin/tasks/cliWorkspaces.php +++ b/workflow/engine/bin/tasks/cliWorkspaces.php @@ -1493,19 +1493,17 @@ function run_artisan($args) if ($workspace !== false) { config(['system.workspace' => $workspace]); + $sw = in_array($args[0], ['queue:work', 'queue:listen']); $tries = $jobsManager->getOptionValueFromArguments($args, "--tries"); - if ($tries === false) { + if ($sw === true && $tries === false) { $tries = $jobsManager->getTries(); + array_push($args, "--tries={$tries}"); } + array_push($args, "--processmakerPath=" . PROCESSMAKER_PATH); - $processmakerPath = PROCESSMAKER_PATH; - $otherOptions = "--processmakerPath={$processmakerPath} "; - - $options = implode(" ", $args) - . " --tries={$tries}"; - CLI::logging("> artisan {$options}\n"); - - passthru(PHP_BINARY . " artisan {$otherOptions} {$options}"); + $command = "artisan " . implode(" ", $args); + CLI::logging("> {$command}\n"); + passthru(PHP_BINARY . " {$command}"); } else { CLI::logging("> The --workspace option is undefined.\n"); }