PMC-963 We need a new artisan command to run the pending jobs, because we need to load the workspace configuration
This commit is contained in:
59
app/Console/Commands/WorkCommand.php
Normal file
59
app/Console/Commands/WorkCommand.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Queue\Console\WorkCommand as BaseWorkCommand;
|
||||
use Illuminate\Queue\Worker;
|
||||
use Maveriks\WebApplication;
|
||||
|
||||
class WorkCommand extends BaseWorkCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* Create a new queue work command.
|
||||
*
|
||||
* @param \Illuminate\Queue\Worker $worker
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Worker $worker)
|
||||
{
|
||||
$this->signature .= '
|
||||
{--workspace=workflow : ProcessMaker Indicates the workspace to be processed.}
|
||||
{--processmakerPath=./ : ProcessMaker path.}
|
||||
';
|
||||
|
||||
$this->description .= ' (ProcessMaker has extended this command)';
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
24
app/Providers/WorkCommandServiceProvider.php
Normal file
24
app/Providers/WorkCommandServiceProvider.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Console\Commands\WorkCommand;
|
||||
use Illuminate\Queue\QueueServiceProvider;
|
||||
|
||||
class WorkCommandServiceProvider extends QueueServiceProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* Overrides "register" method from Queue provider.
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
parent::register();
|
||||
|
||||
//Extend command "queue:work".
|
||||
$this->app->extend('command.queue.work', function ($command, $app) {
|
||||
return new WorkCommand($app['queue.worker']);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use ProcessMaker\Core\JobsManager;
|
||||
use ProcessMaker\Model\Process;
|
||||
use ProcessMaker\Validation\MySQL57;
|
||||
|
||||
@@ -390,6 +391,21 @@ CLI::taskArg("workspace-name", true, true);
|
||||
CLI::taskRun("run_check_queries_incompatibilities");
|
||||
/*********************************************************************/
|
||||
|
||||
/**
|
||||
* This command executes "artisan" loading the workspace connection parameters
|
||||
*/
|
||||
CLI::taskName('artisan');
|
||||
CLI::taskDescription(<<<EOT
|
||||
This command executes "artisan" loading the workspace parameters.
|
||||
Example:
|
||||
./processmaker artisan queue:work --workspace=workflow
|
||||
|
||||
To see other command options please refer to the artisan help.
|
||||
php artisan --help
|
||||
EOT
|
||||
);
|
||||
CLI::taskRun("run_artisan");
|
||||
|
||||
/**
|
||||
* Function run_info
|
||||
*
|
||||
@@ -1463,3 +1479,34 @@ function check_queries_incompatibilities($wsName)
|
||||
echo ">> No MySQL 5.7 incompatibilities in variables found for this workspace." . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function obtains the connection parameters and passes them to the artisan.
|
||||
* All artisan options can be applied. For more information on artisan options use
|
||||
* php artisan --help
|
||||
* @param array $args
|
||||
*/
|
||||
function run_artisan($args)
|
||||
{
|
||||
$jobsManager = JobsManager::getSingleton()->init();
|
||||
$workspace = $jobsManager->getOptionValueFromArguments($args, "--workspace");
|
||||
if ($workspace !== false) {
|
||||
config(['system.workspace' => $workspace]);
|
||||
|
||||
$tries = $jobsManager->getOptionValueFromArguments($args, "--tries");
|
||||
if ($tries === false) {
|
||||
$tries = $jobsManager->getTries();
|
||||
}
|
||||
|
||||
$processmakerPath = PROCESSMAKER_PATH;
|
||||
$otherOptions = "--processmakerPath={$processmakerPath} ";
|
||||
|
||||
$options = implode(" ", $args)
|
||||
. " --tries={$tries}";
|
||||
CLI::logging("> artisan {$options}\n");
|
||||
|
||||
passthru(PHP_BINARY . " artisan {$otherOptions} {$options}");
|
||||
} else {
|
||||
CLI::logging("> The --workspace option is undefined.\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,33 @@ class JobsManager
|
||||
'TASK',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get delay property.
|
||||
* @return int
|
||||
*/
|
||||
public function getDelay()
|
||||
{
|
||||
return $this->delay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tries property.
|
||||
* @return int
|
||||
*/
|
||||
public function getTries()
|
||||
{
|
||||
return $this->tries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get retryAfter property.
|
||||
* @return int
|
||||
*/
|
||||
public function getRetryAfter()
|
||||
{
|
||||
return $this->retryAfter;
|
||||
}
|
||||
|
||||
/**
|
||||
* It obtains a single object to be used as a record of the whole environment.
|
||||
*
|
||||
@@ -70,6 +97,7 @@ class JobsManager
|
||||
|
||||
/**
|
||||
* This initialize environment configuration values.
|
||||
* @return JobsManager
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
@@ -79,6 +107,7 @@ class JobsManager
|
||||
$this->retryAfter = $envs['retry_after'];
|
||||
|
||||
config(['queue.connections.database.retry_after' => $this->retryAfter]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,4 +196,24 @@ class JobsManager
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets the value of the option specified in the second parameter from an
|
||||
* array that represents the arguments.
|
||||
* If the option is not found, it returns false.
|
||||
* @param array $arguments
|
||||
* @param string $option
|
||||
* @return string|boolean
|
||||
*/
|
||||
public function getOptionValueFromArguments($arguments, $option, $allocationSeparator = "=")
|
||||
{
|
||||
$option = $option . $allocationSeparator;
|
||||
$result = preg_grep("/{$option}/", $arguments);
|
||||
if (empty($result)) {
|
||||
return false;
|
||||
}
|
||||
$string = array_pop($result);
|
||||
$value = str_replace($option, "", $string);
|
||||
return trim($value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user