Support the ongoing development of Laravel.io →
Laravel Artisan
Last updated 2 years ago.
0
moderator

Hello @michabbb

If I read the documentation I see an after option. Isn't that what you need?

0

@tvbeek thanks, but your answer would be helpful if my question would have been "is there an after method", but sadly that´s not what I asked.

0

In general, the idea is that cron jobs are stateless and to me the whole concept of using the before and after methods is a bit redundant. Perhaps a better option would be to add a Log::info in the last part of the cron, which would offer you insight into its work.

0
moderator

@tvbeek thanks, but your answer would be helpful if my question would have been "is there an after method", but sadly that´s not what I asked.

@michabbb I missed that you can't access the output in the after function.

To be honest if I need to result of a scheduled task for something I should make that part of the task. And for reporting I listen to the events (See: https://laravel.com/docs/9.x/scheduling#events )

If you want it in the onSuccess and onFailure functions you can write a class that you call from that methods.

0

@tvbeek thanks for your effort, but you are constantly misreading the question. you say "If you want it in the onSuccess and onFailure" - and my question is about "after" and I clearly said I don´t want duplicate code. please read before you answer.

i do know that there are events, but that was not the question here. people in forums tend NOT to answer the question themselves but provide endless alternatives ;)

@aleksamemedovic9 about your suggestion: how should that help if the job fails with an exception? if that happens, there is no logging (except you have an exception handles). the concept of the scheduler is calling stuff as a wrapper to catch all errors, and that is a very good concept. so putting anything into the job itself is totally wrong when it comes to logging the run of schedules jobs itself.

before I get more none helpful feedback, I will answer my question myself: >>> NO <<<

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.