Skip to content

Add debug message on job fail - #101

Open
pstray wants to merge 2 commits into
mojolicious:mainfrom
pstray:add_job_fail_message
Open

Add debug message on job fail#101
pstray wants to merge 2 commits into
mojolicious:mainfrom
pstray:add_job_fail_message

Conversation

@pstray

@pstray pstray commented Oct 3, 2020

Copy link
Copy Markdown

Summary

Just a simple patch to add a debug log on job fail.

Could possibly add some check if there already are on-fail events hooks, but not sure how to do that :)

Motivation

I find it really useful to actually see if a job fail in the terminal running ./app minion worker, and not have to inspect the web interface or add promises or hooks to jobs.

References

Was discussed on #mojo earlier this week

@kraih

kraih commented Oct 3, 2020

Copy link
Copy Markdown
Member

Pretty sure i already said on IRC that this is not the right solution. The Mojo::Job class should not be tied to a Mojolicious app.

@kraih

kraih commented Oct 3, 2020

Copy link
Copy Markdown
Member

The job id is missing from the log message also. And debug is probably not the right level.

@kraih

kraih commented Oct 3, 2020

Copy link
Copy Markdown
Member

Not to mention the lack of tests.

@pstray
pstray force-pushed the add_job_fail_message branch from b052cb9 to 5bf532e Compare October 5, 2020 17:34
@pstray

pstray commented Oct 5, 2020

Copy link
Copy Markdown
Author

Ok, moved the message from Minion/Job.pm to Minion/Command/worker/minion.pm. Sounds like a much more appropriate place for it.

Still no tests though, mostly because I have no idea how to test it :)

Wether it should be debug or some other level can be discussed, but the other messages in that file are debug, and for me, I mostly use such things for debugging. If you really want to do anything with those error messages, I guess you should handle them in other ways in the app itself.

@kraih

kraih commented Oct 5, 2020

Copy link
Copy Markdown
Member

That's a lot of code for what could have been a one-liner.

@pstray

pstray commented Oct 5, 2020

Copy link
Copy Markdown
Author

Removed one of the functions, _dequeue, and fixed the indentation and some spacing to match the other code. Still, a bit more than a one-liner, but that wouldn't be very readable code :)

$worker->on(dequeue => sub { pop->once(spawn => \&_spawn) });
$worker->on(dequeue => sub {
$_[1]->once(failed => \&_failed);
$_[1]->once(spawn => \&_spawn);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use $_[1] over multiple lines.

my($job, $error) = @_;
my($id, $task) = ($job->id, $job->task);
$error =~ s/\n//;
$job->app->log->debug(qq{Job "$id", task "$task" failed: $error});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message format is rather inconsistent.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to provide positive feedback on what a a consistent message should look like instead....

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.

2 participants