robfig / cron

a cron library for go
MIT License
13.14k stars 1.63k forks source link

Feature request: add cron job description to entry #485

Open aymanbagabas opened 1 year ago

aymanbagabas commented 1 year ago

I would like to have some sort of a description of jobs added to the scheduler so that when it logs any entry, it logs the job's description along with the rest of the props.

Instead of AddFunc(spec string, cmd func()) use AddFunc(desc, spec string, cmd func()) to add more context to jobs.

blight19 commented 1 year ago

i think you can save it to database,this is only the basic info in memory.

aymanbagabas commented 1 year ago

My issue is the logger, I want to be able to add context to the logs for a job.

blight19 commented 1 year ago

My issue is the logger, I want to be able to add context to the logs for a job.

when i use it ,i argee with you ,i want to log when the job is start and end.like this

func LogTime(log cron.Logger) cron.JobWrapper {
    return func(j cron.Job) cron.Job {
        return cron.FuncJob(func() {
            start := time.Now()
            defer func(s time.Time) {
                log.Info("this job start at: %s, end at %s\n", start, time.Now())
            }(start)
            j.Run()
        })
    }
}

but don't know which job running

blight19 commented 1 year ago

My issue is the logger, I want to be able to add context to the logs for a job.

when i use it ,i argee with you ,i want to log when the job is start and end.like this

func LogTime(log cron.Logger) cron.JobWrapper {
  return func(j cron.Job) cron.Job {
      return cron.FuncJob(func() {
          start := time.Now()
          defer func(s time.Time) {
              log.Info("this job start at: %s, end at %s\n", start, time.Now())
          }(start)
          j.Run()
      })
  }
}

but don't know which job running

oh,i made a mistake,it can't calc the time , when run it use goroutine.

-< /