1

I want to run my cron job in a specific time for example I want it to run it at 12:31:01 Is it possible?

Here is my code:

$schedule->command('UpdatePriceStatus:pricestatus')->weekdays()->dailyAt('12:31'); 

The documents in laravel doesn't include the seconds. But would it be possible if I do this:

$specificTime = '123101' 
$currentTime  = date('His');
$schedule->command('UpdatePriceStatus:pricestatus')->weekdays()->daily()->when(function () {
      if ($specificTime == $currentTime) {
           return true;
      }
});

or this

$schedule->command('UpdatePriceStatus:pricestatus')->weekdays()->dailyAt('12:31:01');
MicFlurry
  • 25
  • 6
  • Even the `schedule:run` command works only once per minute, this is simply limited by the Linux cron (https://stackoverflow.com/a/9619449/7362396). One thing I can think of (but it's kind of ugly) is to put a offset before your actual logic using `sleep`. E.g. if you want *12:31:01* use `dailyAt('12:31')` and in your code put a `sleep(1)`. – Tobias K. Aug 14 '18 at 09:25
  • Possible duplicate of [How can i use scheduler in seconds manner in Laravel 5.#](https://stackoverflow.com/questions/46701362/how-can-i-use-scheduler-in-seconds-manner-in-laravel-5) – Tobias K. Aug 14 '18 at 09:30
  • @TobiasK Thank you for responding. However I think this only 'kinda good' if you want your cron job to work every seconds or (n) seconds. If I follow the link that you suggested would it work if even if I only want to run my scheduler once per day exactly at 12:31:01? – MicFlurry Aug 14 '18 at 09:43

0 Answers0