Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(job): implement middleware individual config #36

Merged
merged 5 commits into from
Nov 2, 2024
Merged

Conversation

flc1125
Copy link
Owner

@flc1125 flc1125 commented Nov 2, 2024

closed #22

package main

import (
	"context"
	"log"
	"time"

	"github.com/flc1125/go-cron/v4"
	"github.com/flc1125/go-cron/v4/middleware/nooverlapping"
	"github.com/flc1125/go-cron/v4/middleware/recovery"
)

func main() {
	c := cron.New(
		cron.WithSeconds(),
		cron.WithMiddleware(
			recovery.New(),
		),
	)

	c.AddFunc("* * * * * *", func(ctx context.Context) error {
		log.Println("hello")
		time.Sleep(time.Second * 3)
		return nil
	})
	c.AddFunc("* * * * * *", func(ctx context.Context) error {
		log.Println("world")
		time.Sleep(time.Second * 3)
		return nil
	}, nooverlapping.New())

	c.Start()
	defer c.Stop()

	time.Sleep(time.Second * 10)
}

output:

2024/11/02 14:38:38 hello
2024/11/02 14:38:38 world
2024/11/02 14:38:39 hello
2024/11/02 14:38:40 hello
2024/11/02 14:38:41 hello
2024/11/02 14:38:42 hello
2024/11/02 14:38:42 world
2024/11/02 14:38:43 hello
2024/11/02 14:38:44 hello
2024/11/02 14:38:45 hello
2024/11/02 14:38:46 world
2024/11/02 14:38:46 hello
2024/11/02 14:38:47 hello

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Nov 2, 2024
Copy link

codecov bot commented Nov 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.99%. Comparing base (5eb4586) to head (6b9fec5).
Report is 1 commits behind head on 4.x.

Additional details and impacted files
@@           Coverage Diff           @@
##              4.x      #36   +/-   ##
=======================================
  Coverage   96.98%   96.99%           
=======================================
  Files          13       13           
  Lines         764      766    +2     
=======================================
+ Hits          741      743    +2     
  Misses         20       20           
  Partials        3        3           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Nov 2, 2024
@flc1125 flc1125 added this to the v4.1.0 milestone Nov 2, 2024
@flc1125 flc1125 merged commit 908a9a7 into 4.x Nov 2, 2024
17 checks passed
@flc1125 flc1125 deleted the entry-middleware branch November 2, 2024 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

proposal(middleware): configure separate middleware for a separate job
1 participant