Sredny M Casanova
Sredny M Casanova

Reputation: 5053

Configure time of Laravel scheduler from the database

I've a Laravel 5.2 application, I'm using the scheduler to runs a script every 30 minutes by now. But I'm wondering if that time can be retrieved from the database, I want that the admin user configure that time from the webpage, I have the field in the database. But I'm not really sure if the scheduler can update that time from the database, so, is it possible?

Also, I setted: ->sendOutputTo("/var/www/html/laravelProject/public/output")

to save the output in a file named output, but it's not seems that is working even when the cron is executed, I checked the cron log files and there only shows that there is not MTA installed, but I don't want for the moments to send a e-mail, I just want to save the output in a file, so, what am I missing there?

Upvotes: 3

Views: 1554

Answers (1)

sumit
sumit

Reputation: 15464

You can use when The when method may be used to limit the execution of a task based on the result of a given truth test.

 $schedule->command('yourcommand:execute')->everyMinutes()->when(function () {
        if($timefromdb){
            return true;
        }
        else{
            return false;
         }

    });

https://laravel.com/docs/master/scheduling#schedule-frequency-options

Upvotes: 2

Related Questions