Skip to content

Latest commit

 

History

History

cronjob

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

goutils/cronjob

import github.com/pangpanglabs/goutils/cronjob

Getting Started

// Create default cronjob
// Includes some default middlewares
c := cronjob.Default(config.ServiceName, config.BehaviorLog.Kafka)

// Add ContextDB middleware
c.Use(cronjob.ContextDB(config.ServiceName, db, config.Database.Logger.Kafka))

// Add job
c.AddFunc("0 0 1 * * *", func(ctx context.Context) error {
	// Start everyday 1 o'clock
	return nil
})

// Start cron job
log.Println(c.Start())

cronjob.Default

Create cron job with default middleware

  • cronjob.BehaviorLogger - Behavior Log Middleware.
  • cronjob.Recover - Panic Recovery Middleware.

cronjob.New

If you want to create without middleware, use like this.

cronjob.New()

Custom Middleware

If you want to add your own middleware, use like this.

c.Use(func(next cronjob.HandlerFunc) cronjob.HandlerFunc {
	return func(ctx context.Context) error {
		// your middleware logic
		return next(ctx)
	}
})