Merged in bugfix/PMC-964 (pull request #6980)

PMC-964 We need a new artisan command to manage the failed jobs, because we need to load the workspace configuration

Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
Roly
2019-07-19 15:30:31 +00:00
committed by Julio Cesar Laura Avendaño
11 changed files with 218 additions and 40 deletions

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Console\Commands;
use Maveriks\WebApplication;
trait AddParametersTrait
{
/**
* Create a new queue command.
*
* @return void
*/
public function __construct()
{
$this->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();
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Console\Commands;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Queue\Console\FailedTableCommand as BaseFailedTableCommand;
use Illuminate\Support\Composer;
class FailedTableCommand extends BaseFailedTableCommand
{
/**
* The console command name.
*
* @var string
*/
protected $signature = 'queue:failed-table';
/**
* This contains the necessary code to add parameters.
*/
use AddParametersTrait;
/**
* Create a new queue failed-table command.
*
* @return void
*/
public function __construct(Filesystem $files, Composer $composer)
{
$this->signature .= '
{--workspace=workflow : ProcessMaker Indicates the workspace to be processed.}
{--processmakerPath=./ : ProcessMaker path.}
';
$this->description .= ' (ProcessMaker has extended this command)';
parent::__construct($files, $composer);
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Console\Commands;
use Illuminate\Queue\Console\FlushFailedCommand as BaseFlushFailedCommand;
class FlushFailedCommand extends BaseFlushFailedCommand
{
/**
* The console command name.
*
* @var string
*/
protected $signature = 'queue:flush';
/**
* This contains the necessary code to add parameters.
*/
use AddParametersTrait;
}

View File

@@ -0,0 +1,14 @@
<?php
namespace App\Console\Commands;
use Illuminate\Queue\Console\ForgetFailedCommand as BaseForgetFailedCommand;
class ForgetFailedCommand extends BaseForgetFailedCommand
{
/**
* This contains the necessary code to add parameters.
*/
use AddParametersTrait;
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Console\Commands;
use Illuminate\Queue\Console\ListFailedCommand as BaseListFailedCommand;
class ListFailedCommand extends BaseListFailedCommand
{
/**
* The console command name.
*
* @var string
*/
protected $signature = 'queue:failed';
/**
* This contains the necessary code to add parameters.
*/
use AddParametersTrait;
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Console\Commands;
use Illuminate\Queue\Console\RestartCommand as BaseRestartCommand;
class RestartCommand extends BaseRestartCommand
{
/**
* The console command name.
*
* @var string
*/
protected $signature = 'queue:restart';
/**
* This contains the necessary code to add parameters.
*/
use AddParametersTrait;
}

View File

@@ -0,0 +1,14 @@
<?php
namespace App\Console\Commands;
use Illuminate\Queue\Console\RetryCommand as BaseRetryCommand;
class RetryCommand extends BaseRetryCommand
{
/**
* This contains the necessary code to add parameters.
*/
use AddParametersTrait;
}

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Console\Commands;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Queue\Console\TableCommand as BaseTableCommand;
use Illuminate\Support\Composer;
class TableCommand extends BaseTableCommand
{
/**
* The console command name.
*
* @var string
*/
protected $signature = 'queue:table';
/**
* This contains the necessary code to add parameters.
*/
use AddParametersTrait;
/**
* Create a new queue table command.
*
* @return void
*/
public function __construct(Filesystem $files, Composer $composer)
{
$this->signature .= '
{--workspace=workflow : ProcessMaker Indicates the workspace to be processed.}
{--processmakerPath=./ : ProcessMaker path.}
';
$this->description .= ' (ProcessMaker has extended this command)';
parent::__construct($files, $composer);
}
}

View File

@@ -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;
}
}

View File

@@ -80,7 +80,7 @@ return [
*/
'failed' => [
'database' => env('DB_CONNECTION', 'mysql'),
'database' => env('DB_CONNECTION', 'workflow'),
'table' => 'JOBS_FAILED',
],

View File

@@ -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");
}