nestjs / schedule

Schedule module for Nest framework (node.js) ⏰

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feat: use cron name to log error

ndeitch opened this issue · comments

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

Improve unhandled exceptions inside cron tasks.

Describe the solution you'd like

Use cron name if provided as context for log.error message.

Update:

this.logger.error(error);

from: this.logger.error(error)

to: this.logger.error(error, cronName)

cronName would be add as param for wrapFunctionInTryCatchBlocks existing method, it can be null if so, use Scheduler as default

Teachability, documentation, adoption, migration strategy

Not sure about add any tip about this in doc.

What is the motivation / use case for changing the behavior?

Currently when unexpected errors happens only error message is print without much context about where it came from, in big repos with many cron jobs it's hard to find which method thrown the error.

I'm able to implement this PR and understand that it can be considered unnecessary as exceptions should be handled inside each cron.

image

if we implement this, we should change the following somehow

export class ScheduleExplorer implements OnModuleInit {
private readonly logger = new Logger('Scheduler');

so every log entry will have the cron name instead

What do you suggest @micalevisk? Should I open a PR and we discuss about the implementation?

yep, feel free to implement this

Feel free to create a PR for this.