简体   繁体   English

Laravel 队列 PushRaw 延迟?

[英]Laravel Queue PushRaw Delay?

I have an app wherein from laravel 4.2 I am slowly transitioning it to node.我有一个应用程序,其中从 laravel 4.2 开始,我正在慢慢将其转换为节点。

Now I have this Queue::pushRaw(payload, tube) the job is in node and this code is working perfectly fine.现在我有这个Queue::pushRaw(payload, tube)作业在节点中,并且这段代码工作得很好。

However I recently have a problem wherein I need those jobs to have a delay.但是我最近有一个问题,我需要这些工作有延迟。

I use Queue::later before (when my jobs is still in Laravel), but how can I do it with Queue::pushRaw ??我之前使用Queue::later (当我的工作仍在 Laravel 中时),但是如何使用Queue::pushRaw来做到这一点? I can't use Queue::later anymore since I'm passing a raw payload instead of a job.我不能再使用Queue::later因为我传递的是原始有效负载而不是作业。

Base on the documents I can pass options https://laravel.com/api/4.2/Illuminate/Queue/QueueInterface.html根据文件,我可以通过options https://laravel.com/api/4.2/Illuminate/Queue/QueueInterface.html

However, I have no idea what to pass on options to have a delay.但是,我不知道要传递哪些options来延迟。

Upon further investigation, I discovered this file: https://github.com/laravel/framework/blob/4.2/src/Illuminate/Queue/BeanstalkdQueue.php#L66 (I'm using Beanstald) 经过进一步调查,我发现了这个文件: https : //github.com/laravel/framework/blob/4.2/src/Illuminate/Queue/BeanstalkdQueue.php#L66 (我正在使用Beanstald)

You can't really pass a delay since DEFAULT_DELAY is 0. 由于DEFAULT_DELAY为0,因此您无法真正通过延迟。

So my solution is to create a job in Laravel. 因此,我的解决方案是在Laravel中创建工作。

I can then do Queue::later(delay, myJobThatCallsThePushRaw, data, queue); 然后,我可以执行Queue::later(delay, myJobThatCallsThePushRaw, data, queue);

and then on myJobThatCallsThePushRaw I do Queue::pushRaw(my-node-payload) inside. 然后在myJobThatCallsThePushRaw执行Queue::pushRaw(my-node-payload)

Hope this helps someone in the future. 希望这对以后的人有所帮助。

I did this delay in my code, I added a field in database, before I do my job, I check last time of check.If past X second, OK you can do this job, other side requeue with delay.我在我的代码中做了这个延迟,我在数据库中添加了一个字段,在我做我的工作之前,我检查了最后一次检查。如果超过 X 秒,好的,你可以做这个工作,延迟重新排队。

in the consumer of my queue:在我队列的消费者中:

 RabbitmqFacade::consumer('trx_need_to_confirm_check', function ($data) {
                $message = json_decode($data->body, true);


                if ($message['type'] == 1) {
                    $operationResult = $this->tronMainConfirmService->startService($message);
                }
                else {
                    $operationResult = $this->tronMainWithdrawalService->startCheckConfirmService($message);
                }

                if (!$operationResult['ackAble']) {
                    RabbitmqFacade::product('trx_need_to_confirm_check', $message, true, true, 30000);
                }
                $data->ack();
            });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM