Laravel Jobs on Queue行为不端或代码是

时间:2017-09-15 07:12:59

标签: laravel laravel-5 laravel-5.4 beanstalkd

我有一个生产APP,可以根据网络和国家/地区批量发送消息到不同的API。 每次发送消息时,都会将其推送到队列。我们使用Beanstalked和supervisor来监视队列。

这是我的工作处理代码

$tosend = user_messages::with(['recipient' => function ($query) {
            $query->where('api_response', null)->where('status', null);
        }])->find($id);
        $recipients = $tosend->recipient;
        $user = User::find($tosend->user_id);
        $sender = $tosend->senderid;
        $themessage = $tosend->message;

        foreach ($recipients as $recipient) {
            //if user selects to send all sms through corporate route
            if ($tosend->do_corporate == 2) {
                $check = $this->PassRequiredPrecheckCorporate($recipient->recipient, $tosend->route_id, $user);
            } else {
                $check = $this->PassRequiredPrecheck($recipient->recipient, $tosend->route_id, $user);
            }
            $api = api::find($check['api']);
            if ($api->provider_id == 1) {
                $this->ProviderA($recipient, $sender, $themessage, $id, $check['cost'], $api, $tosend->message_type_id, $tosend->sms_pages, $user);
            } elseif ($api->provider_id == 2) {
                $this->ProviderB($recipient, $sender, $themessage, $id, $check['cost'], $api, $tosend->message_type_id, $tosend->sms_pages, $user, $tosend->do_corporate, $tosend->route_id);
            }
        }
        user_messages::where('id', $id)->update([
            'status' => 'Sent'
        ]);

我发现了一个问题,这个问题在金融方面花了很多钱。我意识到,当收件人的数量可能在2000加上收件人时,邮件会多次发送,有时甚至达到10次。 请注意我们每次向$收件人发送消息时都会更新字段“api_response”。

这是我的主管

 [program:app-worker]
    process_name=%(program_name)s_%(process_num)02d
    command=php /home/example/public_html/example.com/artisan queue:work beanstalkd --timeout=60--tries=5
    autostart=true
    autorestart=true
    user=loftysms
    numprocs=10
    redirect_stderr=true
    stdout_logfile=/home/example/public_html/example.com/storage/logs/worker.log

我将感谢我们能得到的每一个帮助

0 个答案:

没有答案