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] Create ScheduleTestCommand #35573

Merged
merged 4 commits into from
Dec 11, 2020
Merged

Conversation

browner12
Copy link
Contributor

Currently, we have a couple ways to run scheduled jobs in our local environments. In Homestead we can enable schedule:run to be enabled for a site. We also have the relatively new schedule:work command that starts a long running worker in your terminal.

I've never turned on scheduling in Homestead, because I don't want the jobs running running around the clock on there. And while schedule:work is nice, chances are you are going to need to manipulate when your commands are scheduled if you want to run some of them. You're not going to wait around for a command that runs at 1AM every morning.

As a (hopefully) simpler alternative, this PR introduces a new command that allows you to execute whichever scheduled task you'd like.

php artisan schedule:test

Screen Shot 2020-12-10 at 10 55 51 PM

Then make your selection, and the scheduled command will run.

Screen Shot 2020-12-10 at 10 56 07 PM

While we are no longer testing the timing aspect of the scheduled job, we are still able to see the side effects from things like sendOutputTo(), hooks, and pings, and we are able to test truth and environment constraints.

present a list of all the registered commands to the users, and execute whichever one they select.
@taylorotwell
Copy link
Member

You need to actually register the command with the framework.

@browner12
Copy link
Contributor Author

Ahh yes, made the same mistake as the guy who created schedule:work. Forgot things weren't auto-registered in core.

Updated now.

@taylorotwell taylorotwell merged commit 7acedc0 into laravel:8.x Dec 11, 2020
@browner12 browner12 deleted the schedule-test branch December 11, 2020 20:02
@kcaj-burr
Copy link

Using invokable objects in the schedule and running the command will display a list of keys only. The keys are not selectable, except pressing return will invoke the first class.

Altering line 36 as below will show the class names of the invokable objects which would be acceptable.

$commandNames[] = $command->command ?? $command->description;

I have not tested this on a clean install.

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.

3 participants