简体   繁体   English

Laravel Schedule Call Helper函数不起作用

[英]Laravel Schedule Call Helper Function Not Working

I'm trying to run a Helper function (App\\Helpers) on a scheduled timer using Laravel (for testing purposes I have it running once every minute). 我正在尝试使用Laravel在计划的计时器上运行助手功能(App \\ Helpers)(出于测试目的,我每分钟运行一次)。 I'm using Laravel 5.3. 我正在使用Laravel 5.3。

This is my schedule function in my Kernel.php... 这是我的Kernel.php中的计划功能。

    protected function schedule(Schedule $schedule)
    {
        $schedule->call(function()
        {
            // Calling this function should write a new file with a random number in it.
            // I know this works perfectly fine outside of the scheduled task because I 
            // call it in other places, and it works)

            FileEdit::UpdateFile();

        })->everyMinute();
    }

The issue is that the FileEdit::UpdateFile() part is NOT ever being called by the laravel at the designated time intervals. 问题在于, FileEdit::UpdateFile()从未在指定的时间间隔调用FileEdit::UpdateFile()部分。

Are you running a cron job to execute the schedule command every minute? 您是否正在运行cron作业以每分钟执行一次schedule命令?

https://laravel.com/docs/5.5/scheduling#introduction https://laravel.com/docs/5.5/scheduling#introduction

* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1

This Cron will call the Laravel command scheduler every minute. 该Cron将每分钟调用一次Laravel命令调度程序。 When the schedule:run command is executed, Laravel will evaluate your scheduled tasks and runs the tasks that are due. 执行schedule:run命令后,Laravel将评估您的计划任务并运行到期的任务。

Your code looks fine, assuming you have cron configured correctly, this may help you debug your issue https://laravel.com/docs/5.5/scheduling#task-hooks 假设您正确配置了cron,您的代码看起来不错,这可以帮助您调试问题https://laravel.com/docs/5.5/scheduling#task-hooks

Still I would double check if your cron is working, and set according to https://laravel.com/docs/5.5/scheduling#introduction 我仍然会再次检查您的cron是否正常工作,并根据https://laravel.com/docs/5.5/scheduling#introduction进行设置

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

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