我创建了一个Laravel作业,以便在特定的日期和时间(例如,明天)执行。我想添加一个手动按钮,该按钮覆盖时间,并在其设置的执行时间之前执行排队作业。单击该按钮将创建一个ajax调用,并向服务器发送一个作业ID。这将导致作业在今天而不是明天执行。
我们可以使用以下命令手动重试失败的作业:php artisan queue:retry JOBIDHERE
我不知道该使用什么来执行排队的作业。
我可以获得作业ID,但我不知道是否有可能在Laravel作业设定的执行时间之前执行它。
我在谷歌上搜索,但没有找到任何有这样的问题和解决方案的人。
我用的是Laravel Ver 5.8。使用Mysql 5.7
更新:
下面是排队作业的有效负载。
我尝试使用Json并对其进行解码,但我不确定是否可以更新该队列的命令,以便更新队列的日期和时间,并将其保存回排队作业记录。
{"displayName":"App\\Jobs\\Payway\\UpdateCustomerInvestment","job":"Illuminate\\Queue\\CallQueuedHandler@call","maxTries":null,"delay":null,"timeout":null,"timeoutAt":null,"data":{"commandName":"App\\Jobs\\Payway\\UpdateCustomerInvestment","command":"O:40:\"App\\Jobs\\Payway\\UpdateCustomerInvestment\":17:{s:57:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000transactionType\";s:7:\"payment\";s:57:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000principalAmount\";d:9999;s:56:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000customerNumber\";s:4:\"BR-2\";s:50:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000currency\";s:3:\"aud\";s:58:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000singleUseTokenID\";N;s:55:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000payway_helper\";O:29:\"App\\Http\\Helpers\\PaywayHelper\":0:{}s:54:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000impodenceKey\";s:36:\"afedfc34-d08e-4831-a4aa-29de930d6b98\";s:49:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000headers\";a:0:{}s:60:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000localInvestmentObj\";O:45:\"Illuminate\\Contracts\\Database\\ModelIdentifier\":4:{s:5:\"class\";s:33:\"App\\Models\\Investment\\Investments\";s:2:\"id\";i:374;s:9:\"relations\";a:2:{i:0;s:8:\"investor\";i:1;s:13:\"investor.user\";}s:10:\"connection\";s:5:\"mysql\";}s:54:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000paywayTotals\";O:45:\"Illuminate\\Contracts\\Database\\ModelIdentifier\":4:{s:5:\"class\";s:38:\"App\\Models\\Banking\\Payway\\PaywayTotals\";s:2:\"id\";i:1;s:9:\"relations\";a:0:{}s:10:\"connection\";s:5:\"mysql\";}s:6:\"\u0000*\u0000job\";N;s:10:\"connection\";N;s:5:\"queue\";s:6:\"payway\";s:15:\"chainConnection\";N;s:10:\"chainQueue\";N;s:5:\"delay\";O:13:\"Carbon\\Carbon\":3:{s:4:\"date\";s:26:\"2019-11-12 23:35:22.752222\";s:13:\"timezone_type\";i:3;s:8:\"timezone\";s:16:\"Australia\/Sydney\";}s:7:\"chained\";a:0:{}}"}}更新2:
当我反序列化有效载荷命令时,我得到了以下信息。

因此,我正在努力更新这个延迟日期,希望它能起作用。
但从“朱利安·斯塔克”的回答来看,我可能也必须更新available_at。
我的理论是,当队列运行时,它将寻找基于available_at的作业。但是,当作业正在执行并且有延迟时,它可能不会在特定的时间执行。这个理论还有待检验。
我将更新这两个dateTimes,并检查是否一切顺利。
发布于 2019-11-12 08:18:45
在类似的用例中,我刚刚更新了作业available_at时间,所以queue:listen命令会尽快执行作业。
DB::table('jobs')->where('id', $jobId)->update(['available_at' => time()]);我不知道这是不是正确的方法,但它对我有效
发布于 2019-11-15 12:29:50
要做到这一点,您所要做的就是首先解码您的有效载荷,这将是
{
"displayName":"App\\Jobs\\Payway\\UpdateCustomerInvestment",
"job":"Illuminate\\Queue\\CallQueuedHandler@call",
"maxTries":null,
"delay":null,
"timeout":null,
"timeoutAt":null,
"data":{
"commandName":"App\\Jobs\\Payway\\UpdateCustomerInvestment",
"command":"O:40:\"App\\Jobs\\Payway\\UpdateCustomerInvestment\":17:{s:57:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000transactionType\";s:7:\"payment\";s:57:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000principalAmount\";d:9999;s:56:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000customerNumber\";s:4:\"BR-2\";s:50:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000currency\";s:3:\"aud\";s:58:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000singleUseTokenID\";N;s:55:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000payway_helper\";O:29:\"App\\Http\\Helpers\\PaywayHelper\":0:{}s:54:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000impodenceKey\";s:36:\"afedfc34-d08e-4831-a4aa-29de930d6b98\";s:49:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000headers\";a:0:{}s:60:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000localInvestmentObj\";O:45:\"Illuminate\\Contracts\\Database\\ModelIdentifier\":4:{s:5:\"class\";s:33:\"App\\Models\\Investment\\Investments\";s:2:\"id\";i:374;s:9:\"relations\";a:2:{i:0;s:8:\"investor\";i:1;s:13:\"investor.user\";}s:10:\"connection\";s:5:\"mysql\";}s:54:\"\u0000App\\Jobs\\Payway\\UpdateCustomerInvestment\u0000paywayTotals\";O:45:\"Illuminate\\Contracts\\Database\\ModelIdentifier\":4:{s:5:\"class\";s:38:\"App\\Models\\Banking\\Payway\\PaywayTotals\";s:2:\"id\";i:1;s:9:\"relations\";a:0:{}s:10:\"connection\";s:5:\"mysql\";}s:6:\"\u0000*\u0000job\";N;s:10:\"connection\";N;s:5:\"queue\";s:6:\"payway\";s:15:\"chainConnection\";N;s:10:\"chainQueue\";N;s:5:\"delay\";O:13:\"Carbon\\Carbon\":3:{s:4:\"date\";s:26:\"2019-11-12 23:35:22.752222\";s:13:\"timezone_type\";i:3;s:8:\"timezone\";s:16:\"Australia\/Sydney\";}s:7:\"chained\";a:0:{}}"
}
}当您解码了有效负载后,您将看到“命令”是序列化的,因此接下来您必须取消“命令”的序列化。
[delay] => Array
(
[date] => 2019-11-12 23:35:22.752222
[timezone_type] => 3
[timezone] => Australia/Sydney
)然后,您可以在延迟节点下更新日期,并且可以使用Carbon或PHP,根据需要更新日期。完成此操作后,只需再次序列化“命令”节点,然后将整个有效负载json_encode并保存。
您还需要遵循@Julian的回答,即修改该作业的available_at。
我希望这能帮到你。
发布于 2019-11-14 12:03:16
更新排队作业的时间将是错误的做法,而不是您可以刷新计划作业并立即运行调度函数。
https://stackoverflow.com/questions/58772246
复制相似问题