doudi2005 2018-05-08 17:16
浏览 50
已采纳

Laravel 5.6删除代码中的日程表

I have a API where a user create integrations.

Those integrations may have recurrence (repeat every 6 months, every 2 days, etc).

  • In the UI when the user selects when to repeat is generated a cron (ex: * * * * *).
  • The recurrence is managed by the laravel schedule (https://laravel.com/docs/5.6/scheduling)
  • That cron is saved in the configurations of that integration of the user

EX: then in the Kernel.php :

$schedule->job(new IntegrateJob, 'integrationId')->cron('* * * * *');

Easy... I works!!!

But if the user deletes the integrations (soft delete), then I dont want to run that job in the selected cron.

I want to delete that entry in the laravel scheduler.

But that info is not saved anywhere, not in the database, not in cache, not in the redis server that manages the jobs...

If I cant find them I cant delete them... Any Solutions? Thank U

  • 写回答

1条回答 默认 最新

  • doubi9999 2018-05-08 18:38
    关注

    I think the proper way to do this would be changing your design so the event runs for all the users and then determines which user(s) to run the event for (if any). Also, the way Laravel handles scheduled tasks in different than the way Linux handles Cron jobs.

    As an example:

    If you have the following code in the app/Console/Kernel.php file and run php artisan schedule:run, the job is ran.

    $schedule->job(new IntegrateJob, 'integrationId')->cron('* * * * *');
    

    If you take out the above code and run php artisan schedule:run after a minute, the job will not be ran because Laravel does not persist the job.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵