raveren's avatar

Schedule between() not working as expected

I noticed that when scheduling commands the between() method seems to not be doing anything.

I use the example from the docs (laravel.com/docs/10.x/scheduling#between-time-constraints):

        $schedule->command('emails:send')
            ->hourly()
            ->between('7:00', '22:00');

And launch

php artisan schedule:list
  0 * * * *    php artisan emails:send ......................... Next Due: in 8 Minutes

I double verified it by installing a fresh Laravel app:

i.imgur.com/PQcbISs.png

As you can see the configuration resolves itself to just hourly, is this a bug or am I missing something?

0 likes
3 replies
Snapey's avatar

depends what time you ran the list command. If between 7am and 22:00 then the answer is correct

raveren's avatar

@Snapey look at the expression at the front of the output, not the help text.

It resolves to 0 * * * * which is every hour, while the expected output should have been 0 7-22 * * *.

Also, if I change the timespan to not include current time, it would still say "in 8 Minutes", I tested that too, my question is if I am missing something obscure from the configuration, or is it a genuine bug with Laravel.

I was asked to post here when submitting a bug: github.com/laravel/framework/issues/50120

s4muel's avatar
s4muel
Best Answer
Level 50

between() works fine, just the schedule:list command does not display it OK. the tasks are not translated to individual cron entries, so the cron representation is a bit misleading (and wrong in this case). the kernel is run every minute (via cron) and it checks the schedule internally and run respective tasks/commands. and since it is not translated to the cron syntax (edit: well, it might, but i am not going to dig into it:), i just think it would be pain to represent all of the contraints that laravel scheduler provides.

someone tried to improve it, but unfortunately... https://github.com/laravel/framework/pull/47983

3 likes

Please or to participate in this conversation.