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']);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user