Laravel-为每个高级用户安排工作
用户购买高级时,我需要做的事情
,我给他保费。每周,我都需要在订阅时间再次提供保费。但是,如果用户不再是订户,则他们不应再收到保费。
我认为我需要使用计划的任务
,但我不知道如何以正确的方式做到这一点。
- 如何动态添加任务?
- 我需要将任务放在数据库任务表中吗?
- 如果未订阅用户,如何删除任务? (检查是在我的工作中进行的,但是如果退缩,如何删除任务)
代码
我需要运行此任务。
$schedule->job(new CreditPremiumUser($userId))-> weeklyOn(1, '10:42:53');
// 1 = premium purchase day
// '10:42:53' = subscription time
What I need to do
When user purchase premium, I give him premium money. Every week, I need to give premium money again at subscription time. However, if the user is no longer a subscriber, they should no longer receive their premium money.
Questions
I think I need to use scheduled tasks, but I do not know how to do that on right way.
- How to add tasks dynamically ?
- Do I need to put the tasks in the database tasks table ?
- How to remove task if user is unsubscribed ? (the check is made in my job but how to remove the task if is unsubscribe)
Code
I need to run this task.
$schedule->job(new CreditPremiumUser($userId))-> weeklyOn(1, '10:42:53');
// 1 = premium purchase day
// '10:42:53' = subscription time
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我确实
表任务
创建了需要安排作业的 ,因此我有
job_name
列。例如,根据您的需求,如果要安排命令的执行,则可以添加
command_name
列。内核
在您的 App \ Console \ kernel.php
附表
方法写作中更新 类型逻辑(如果需要类型)。
尝试
将所有任务添加到数据库中。
本地
运行命令
PHP工匠时间表:工作
,调度程序将运行以在计划的Datatime上处理您的任务生产
像在这里
在每个环境上,调度程序将每分钟运行,并检查是否存在
任务
表中执行的任务。What i did
Create table tasks
I need to schedule Job so I have
job_name
column.For example, depending on your needs, you can add
command_name
column if you want to schedule the execution of a command.Update Kernel
In your App\Console\Kernel.php
schedule
method write:You can remove
type
condition if you do not need it or add multiple types logic if you need type.Try It
Add all your tasks to your database.
Local
Run command
php artisan schedule:work
and the scheduler will run to process your tasks at the scheduled dataTimeProduction
Add CRON to your server like here
On each environment, the scheduler will run every minute and check if there are tasks to execute in
tasks
table.