laravel 从不同的代码库推送排队的作业
laravel push queued jobs from different codebase
我正在尝试从其他代码库触发作业
我的命令Class:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Foundation\Bus\DispatchesJobs;
use App\Jobs\MyJob;
class EncodeTvVideos extends Command
{
use DispatchesJobs;
protected $signature = 'command:my';
protected $description = '';
public function handle()
{
$job = (new MyJob($this->argument()))
->onConnection('beanstalkd')
->onQueue('cron-default'));
$this->dispatch($job);
}
}
和我的工作Class:
<?php namespace App\Jobs;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class MyJob extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $payload;
public function __construct($payload = null)
{
$this->payload = $payload;
}
public function handle()
{
echo "Job processed here";
$this->job->delete();
}
}
我正在使用 queue:listen 命令收听我的队列,例如
php artisan queue:listen --queue=cron-default
如果我 运行 命令(在一些代码库中)command:my 我得到这样的有效负载任何处理成功。
{
"job":"Illuminate\\Queue\\CallQueuedHandler@call",
"data":{
"command":"O:29:\"Acme\Jobs\FooJob\":4:{s:11:\"fooBar\";s:7:\"abc-123\";s:5:\"queue\";N;s:5:\"delay\";N;s:6:\"\u0000*\u0000job\";N;}"
}
}
现在我的问题是我需要从其他代码库触发这个作业或命令,有什么办法吗?
我没有(commands/workers 项目)的域名,否则我可以尝试创建一个路由,它将触发命令。
在此得到帮助ref
通过使用这些包 "illuminate/queue": "5.2.", "pda/pheanstalk": "~3.0", "illuminate/encryption": "5.2. “
我可以像这样将普通有效负载推送到给定的管子
use Illuminate\Queue\Capsule\Manager as Queue;
$queue = new Queue;
// Some drivers need it
$queue->getContainer()->bind('encrypter', function() {
return new Illuminate\Encryption\Encrypter('foobar');
});
$queue->addConnection([
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
], 'default');
$queue->push('App\Jobs\MyJob@process', ['data'=> 'something']);
//第一个参数JobClass在其他代码库中的完整路径
//第二个参数Job的任何参数。
我的作业中的小修改以处理这两个命令和普通负载
<?php namespace App\Jobs;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class MyJob extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $payload;
public function __construct($payload = null)
{
$this->payload = $payload;
}
public function handle()
{
echo "Job processed here";
$this->job->delete();
}
public function process($job, $payload)
{
echo "Job processed from plain payload";
$job->delete();
}
}
我正在尝试从其他代码库触发作业
我的命令Class:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Foundation\Bus\DispatchesJobs;
use App\Jobs\MyJob;
class EncodeTvVideos extends Command
{
use DispatchesJobs;
protected $signature = 'command:my';
protected $description = '';
public function handle()
{
$job = (new MyJob($this->argument()))
->onConnection('beanstalkd')
->onQueue('cron-default'));
$this->dispatch($job);
}
}
和我的工作Class:
<?php namespace App\Jobs;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class MyJob extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $payload;
public function __construct($payload = null)
{
$this->payload = $payload;
}
public function handle()
{
echo "Job processed here";
$this->job->delete();
}
}
我正在使用 queue:listen 命令收听我的队列,例如
php artisan queue:listen --queue=cron-default
如果我 运行 命令(在一些代码库中)command:my 我得到这样的有效负载任何处理成功。
{
"job":"Illuminate\\Queue\\CallQueuedHandler@call",
"data":{
"command":"O:29:\"Acme\Jobs\FooJob\":4:{s:11:\"fooBar\";s:7:\"abc-123\";s:5:\"queue\";N;s:5:\"delay\";N;s:6:\"\u0000*\u0000job\";N;}"
}
}
现在我的问题是我需要从其他代码库触发这个作业或命令,有什么办法吗?
我没有(commands/workers 项目)的域名,否则我可以尝试创建一个路由,它将触发命令。
在此得到帮助ref
通过使用这些包 "illuminate/queue": "5.2.", "pda/pheanstalk": "~3.0", "illuminate/encryption": "5.2. “
我可以像这样将普通有效负载推送到给定的管子
use Illuminate\Queue\Capsule\Manager as Queue;
$queue = new Queue;
// Some drivers need it
$queue->getContainer()->bind('encrypter', function() {
return new Illuminate\Encryption\Encrypter('foobar');
});
$queue->addConnection([
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
], 'default');
$queue->push('App\Jobs\MyJob@process', ['data'=> 'something']);
//第一个参数JobClass在其他代码库中的完整路径 //第二个参数Job的任何参数。
我的作业中的小修改以处理这两个命令和普通负载
<?php namespace App\Jobs;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class MyJob extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $payload;
public function __construct($payload = null)
{
$this->payload = $payload;
}
public function handle()
{
echo "Job processed here";
$this->job->delete();
}
public function process($job, $payload)
{
echo "Job processed from plain payload";
$job->delete();
}
}