hmazter / laravel-schedule-list

Laravel package to add command to list all scheduled artisan commands
MIT License
94 stars 14 forks source link

Get the result as an array (or object array) #9

Closed rap2hpoutre closed 6 years ago

rap2hpoutre commented 6 years ago

It could be great to add an helper function (or something like that) to get the scheduled tasks as an array. So we could display it in a web interface, or iterate over it to check some things.

rap2hpoutre commented 6 years ago

OK, I think I found a way to do this (return a collection with data from Scheduler).

I could make a PR about it.

I propose to create a helper for this: are you OK with schedule_list? (a helper seems simpler than create a class for this, but as you want: I can also create a class with a method like Hmazter\LaravelScheduleList\ScheduleList::all() or (new Hmazter\LaravelScheduleList\ScheduleList)->all().

hmazter commented 6 years ago

I get all the data from \Illuminate\Console\Scheduling\Schedule::events and that is public if you just need the raw data. But I guess you are after some of the formatted and parsed data that I have? I could extract the logic with a public getter to a class, which would return pretty much this data https://github.com/hmazter/laravel-schedule-list/blob/8f68139ab3b664f36c3eddf1ff710bbaecdd889c/src/Console/ListScheduler.php#L118-L123 And then use that in the command

hmazter commented 6 years ago

This is a first, very basic attempt to what you may ask: https://github.com/hmazter/laravel-schedule-list/pull/10

With this you could do:

$scheduledEvents = app()->make(ScheduleList::class)->all(); // or use injection

$scheduledEvents would then contain all the scheduled events with all the parsed and formatted data previously used in the command line output

hmazter commented 6 years ago

Now available in v1.0.0

rap2hpoutre commented 6 years ago

Thanks!