Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Adds "schedule:work" command #34618

Merged
merged 4 commits into from
Oct 1, 2020
Merged

Conversation

hivokas
Copy link
Contributor

@hivokas hivokas commented Oct 1, 2020

Right now there are 2 options to test the scheduler:

  • run schedule:run by hand every minute (that's annoying);
  • add the Cron entry to the system (you probably don't want to do that just to test the things).

This new schedule:work command emulates the second option by running schedule:run command every minute under the hood.
When you want to stop the worker, just use Ctrl+C.

Inspired by laravel/ideas#2338

@driesvints
Copy link
Member

The scheduler was meant to be used in combination with a daemon that runs it every minute and obviously not manually by hand 😅

@hivokas
Copy link
Contributor Author

hivokas commented Oct 1, 2020

The scheduler was meant to be used in combination with a daemon that runs it every minute and obviously not manually by hand 😅

Yeah, I know 😅 But I'm talking about the cases when you just want to test something & don't want to add the Cron entry to the system for this testing.

@driesvints
Copy link
Member

Ah I see. Hmm yeah could be cool actually! Wondering if we can't just add a --daemon flag to the schedule:run command instead of a new command?

@hivokas
Copy link
Contributor Author

hivokas commented Oct 1, 2020

Wondering if we can't just add a --daemon flag to the schedule:run command instead of a new command?

Let's see what others think. I'd rather leave a schedule worker as a separate command to avoid the complexity of schedule:run command.

Illia Sakovich added 2 commits October 1, 2020 15:28
@taylorotwell
Copy link
Member

Don't you need to register the command with the framework?

@hivokas
Copy link
Contributor Author

hivokas commented Oct 1, 2020

Don't you need to register the command with the framework?

Oh, I forgot about that because Laravel automatically detects commands inside the application 😅
I'll register it and update the PR shortly.

@hivokas
Copy link
Contributor Author

hivokas commented Oct 1, 2020

@taylorotwell I've updated the PR

@ottoszika
Copy link
Contributor

I think this feature should be just for local development and not for production. It could behave differently than traditional Unix cron jobs.
Just an example:

  • Job A, running at 08:00 PM
  • Job B, running at 08:05 PM

If Job A is a long-running one with a 10m duration, we just lose the due time of the Job B, and it won't be handled.
In other words: jobs will need to wait for each other.

@TitasGailius
Copy link
Contributor

This is hot 🔥. Previously, I was running this command to basically achieve the same thing:

while true; do php artisan schedule:run; sleep 60; done

@hivokas
Copy link
Contributor Author

hivokas commented Oct 9, 2020

@ottoszika check it out #34736

@kheme
Copy link

kheme commented Oct 12, 2020

Will this also be coming to Lumen?

@laravel laravel deleted a comment Nov 15, 2020
@laravel laravel deleted a comment Nov 15, 2020
@laravel laravel deleted a comment Nov 15, 2020
@samuelcecilio
Copy link

@hivokas can i use this in production?

// start.sh

composer dump-autoload --optimize
php /var/www/artisan optimize
php /var/www/artisan migrate --no-interaction --force
supervisord -c /var/www/supervisord.conf
// supervisord.conf

...

[program:schedule]
command=php /var/www/artisan schedule:work
autorestart=true
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile_maxbytes=0
stderr_logfile_maxbytes=0
stdout_logfile=/dev/stdout
stderr_logfile=/dev/stderr
stopwaitsecs=3600

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants