登录  /  注册
Laravel,将数据库队列限制为每分钟 1 封电子邮件
P粉310931198
P粉310931198 2023-12-13 14:53:22
[PHP讨论组]

我的应用程序托管在共享托管平台上,该平台限制每小时 200 封电子邮件。

我的应用程序正在运行数据库连接驱动程序,并且作业表中有 3000 个作业。

我想限制此队列,使其每 30 秒或 1 分钟仅发送 1 封电子邮件,以确保我的托管不会出现问题。

研究: 我尝试过本教程的延迟、此问题的速率限制但没有响应、此 laravel 文档的延迟作业,但没有任何效果。

问题:有没有办法像在redis队列连接中那样限制数据库队列连接中的队列,即

// Allow only 1 email every 30 seconds
Redis::throttle('any_key')->allow(1)->every(30)->then(function () {
    Mail::to($this->email)->send(new NotificationEmail($this->data) );
    Log::info('Emailed order ' . $this->email);
}, function () {
    // Could not obtain lock; this job will be re-queued
    return $this->release(2);
});

我的实现:仅延迟第一个作业,然后立即发送其他作业

public function sendEmailNotification($email,$data)
{
    //Send email to user and to admin
    $email_job = (new ProcessEmailNotificationJob($email,$data))->delay(now()->addSeconds(30));
    
    if($this->dispatch($email_job)){
        return true;
    }
    else{
        return false;
    }
}

**ENV 文件:**

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=database
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

P粉310931198
P粉310931198

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 //m.sbmmt.com/ All Rights Reserved | php.cn | 湘ICP备2023035733号