我有一份工作要执行,将短信发送给用户。我想在指定的队列名称上运行此作业。例如,此作业已添加到“ SMS ”队列中。所以我找到了一种方法,但是存在一些错误。
创建作业实例并使用onQueue()函数执行以下操作:
$resetPasswordJob = new SendGeneratedPasswordResetCode(app()->make(ICodeNotifier::class), [
'number' => $user->getMobileNumber(),
'operationCode' => $operationCode
]);
$resetPasswordJob->onQueue('SMS');
$this->dispatch($resetPasswordJob);
Run Code Online (Sandbox Code Playgroud)
我的Job班级是这样的:
class SendGeneratedPasswordResetCode implements ShouldQueue
{
use InteractsWithQueue, Queueable;
/**
* The code notifier implementation.
*
* @var ICodeNotifier
*/
protected $codeNotifier;
/**
* Create the event listener.
*
* @param ICodeNotifier $codeNotifier
* @return self
*/
public function __construct(ICodeNotifier $codeNotifier)
{
$this->codeNotifier = $codeNotifier;
}
/**
* Handle the event.
*
* @return void
*/
public function handle()
{
echo …Run Code Online (Sandbox Code Playgroud) 因此,我正在尝试优化网站,并在每次加载和退出页面时都保存一个指标(页面停留时间,IP地址等)进行分析。但是,这些是我服务器上相当大的瓶颈。当查看运行我的整个功能所需的时间时,整个函数大约需要1-2ms,然后保存到数据库大约需要100-200ms。因此,我的目标是运行我的函数,然后调度新任务,这将完成指标的实际保存。这样,所有保存的模型都可以卸载到队列中。以下是我的工作副本
class SaveMetric implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle(Metrics $metric)
{
//
$metric->save();
}
}
Run Code Online (Sandbox Code Playgroud)
然后在获取所有需要的值后在控制器功能中运行此命令
dispatch(new SaveMetric($newMetric));
Run Code Online (Sandbox Code Playgroud)
这似乎可以运行,但似乎无能为力。我想念什么吗?(编辑)这样做〜某事〜它只是将一条记录保存到DB中所有字段中都为null,就像我创建了一个没有任何值的新指标一样。
我使用工匠make:job命令创建了作业
我在5.3.31上
所以它不能与
https://github.com/laravel/framework/issues/15179
经过300个工作后,我得到:
[2017-04-11 13:51:53] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function beginTransaction() on null in /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Database/Connection.php:612
Stack trace:
#0 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php(175): Illuminate\Database\Connection->beginTransaction()
#1 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(175): Illuminate\Queue\DatabaseQueue->pop('default')
#2 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(145): Illuminate\Queue\Worker->getNextJob(Object(Illuminate\Queue\DatabaseQueue), 'default')
#3 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(75): Illuminate\Queue\Worker->runNextJob('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#4 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(100): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#5 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(83): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#6 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
#7 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(508): call_user_func_array(Array, Array)
#8 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Console/Command.php(169): Illuminate\Container\Container->call(Array)
#9 /var/www/html/www.myapp.com/vendor/symfony/console/Command/Command.php(256): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 /var/www/html/www.myapp.com/vendor/symfony/console/Application.php(820): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /var/www/html/www.myapp.com/vendor/symfony/console/Application.php(187): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /var/www/html/www.myapp.com/vendor/symfony/console/Application.php(118): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(121): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) …Run Code Online (Sandbox Code Playgroud) 我希望我的laravel队列:在共享主机上继续运行的工作,这是共享主机(不是在VPS上),我什么都不能安装,因为在搜索此建议时几乎所有在线资源都建议安装主管。所以基本上我以为我可以创建一个cron作业,检查队列是否未运行并启动它,有关如何执行此操作的任何帮助,因为有点卡住了,谢谢。
Linux服务器和Laravel 5.3上的PS Am
下面是我运行php artisan队列时发生的事情:listen和我的工作表上只有一份工作
这是我的代码:
public function handle(Xero $xero)
{
$this->getAndCreateXeroSnapshotID();
$this->importInvoices($xero);
$this->importBankTransaction($xero);
$this->importBankStatement($xero);
$this->importBalanceSheet($xero);
$this->importProfitAndLoss($xero);
}
Run Code Online (Sandbox Code Playgroud) 我有两个由两个工作人员监控的 Amazon SQS 队列。我用它来发送电子邮件,发送一些工人请求。典型的后端东西。本月必须有大约 100 个工作岗位。
但是,我收到了来自 Amazon 的电子邮件,说我已经达到了 887,457 个免费等级 1,000,000 个 Amazon Simple Queue Service 请求的请求。
我想知道我是如何得到这个数字的?工作人员是否轮询被视为请求的队列?如果是这样,我们可以增加这个间隔吗?
我有一个这样的时间表:
<?php
namespace App\Console;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Console\Scheduling\Schedule;
protected function schedule(Schedule $schedule)
{
Artisan::call('queue:work');
}
Run Code Online (Sandbox Code Playgroud)
我在我的 cronjob 上添加了这个:
* * * * * cd /var/www/html/my_script_address && php artisan schedule:run
它是正确的代码吗?我在问,因为每一分钟都在奔跑Artisan::call('queue:work')。
这是最好的方法吗?
我的网站将发送作业的电子邮件排队到jobs表中。我认为电子邮件服务器存在一些问题,它无法发送电子邮件,因此作业被卡在作业表中。现在也许有太多的工作,并且我收到此错误消息:
Next exception 'Illuminate\Database\QueryException' with message 'SQLSTATE[22003]: Numeric value out of range: 1264 Out of range value for column 'attempts' at row 1 (SQL: update `jobs` set `reserved_at` = 1510263884, `attempts` = 256 where `id` = 342)' in /var/www/vhosts/parcgilley.com/httpdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php:647
#0 /var/www/vhosts/parcgilley.com/httpdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php(607): Illuminate\Database\Connection->runQueryCallback('update `jobs` s...', Array, Object(Closure))
#1 /var/www/vhosts/parcgilley.com/httpdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php(477): Illuminate\Database\Connection->run('update `jobs` s...', Array, Object(Closure))
#2 /var/www/vhosts/parcgilley.com/httpdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php(416): Illuminate\Database\Connection->affectingStatement('update `jobs` s...', Array)
Run Code Online (Sandbox Code Playgroud)
所以我想知道如何刷新所有排队的作业以清除表?我无法访问数据库以删除表中的数据,因此有命令行吗?我没有失败的队列表。
我需要在侦听器上的特定失败作业之间设置延迟。我知道如果指定选项它的工作原理,但我需要监听器--delay=5上的特定延迟(而不是标准作业)。我尝试将该属性放在侦听器上,但不起作用。delay
<?php
namespace Froakie\Listeners;
use Carbon\Carbon;
use Froakie\Events\ExampleEvent;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
/**
* Class ExampleListener
*
* @package Froakie\Listeners
* @author Miguel Borges <miguel.borges@edirectinsure.com>
*/
class ExampleListener implements ShouldQueue
{
use InteractsWithQueue;
/**
* The number of seconds the job can run before timing out.
*
* @var int
*/
public $timeout = 5;
/**
* The number of times the job may be attempted.
*
* @var int
*/
public $tries = …Run Code Online (Sandbox Code Playgroud) 在我的本地服务器中,我可以毫无问题地使用队列,只需使用:
php artisan queue:work。
但在我的 AWS 服务器中,队列没有运行。
我的连接队列是database并且同步邮件发送没有问题。
我检查了作业表,可以看到我的队列,但由于未知原因它从未运行。
是否需要在AWS Elastic Beanstalke服务器中进行一些不同的配置?
我尝试过手动使用
php artisan queue:listen
php artisan queue:work
Run Code Online (Sandbox Code Playgroud)
两者都失败了。
amazon-web-services laravel amazon-elastic-beanstalk laravel-queue
laravel-queue ×10
laravel ×9
laravel-5 ×6
php ×3
amazon-sqs ×1
laravel-5.1 ×1
laravel-5.5 ×1
queue ×1
task-queue ×1