@@ -15,13 +15,16 @@ import (
15
15
"github.com/flanksource/duty/context"
16
16
"github.com/google/gops/agent"
17
17
"github.com/labstack/echo/v4"
18
+ cmap "github.com/orcaman/concurrent-map/v2"
18
19
"github.com/robfig/cron/v3"
19
20
)
20
21
21
- var Crons [] * cron.Cron
22
+ var Crons = cmap . New [ * cron.Cron ]()
22
23
23
24
func RegisterCron (cron * cron.Cron ) {
24
- Crons = append (Crons , cron )
25
+
26
+ // Cache cron objects by their pointer
27
+ Crons .SetIfAbsent (fmt .Sprintf ("%p" , cron ), cron )
25
28
}
26
29
27
30
func init () {
@@ -115,8 +118,8 @@ func AddDebugHandlers(e *echo.Echo, rbac echo.MiddlewareFunc) {
115
118
debug .POST ("/cron/run" , func (c echo.Context ) error {
116
119
name := c .Request ().FormValue ("name" )
117
120
names := []string {}
118
- for _ , cron := range Crons {
119
- for _ , e := range cron .Entries () {
121
+ for entry := range Crons . IterBuffered () {
122
+ for _ , e := range entry . Val .Entries () {
120
123
entry := toEntry (& e )
121
124
names = append (names , entry .GetName ())
122
125
if entry .GetName () == name {
@@ -172,8 +175,8 @@ func toEntry(e *cron.Entry) JobCronEntry {
172
175
func CronDetailsHandler () func (c echo.Context ) error {
173
176
return func (c echo.Context ) error {
174
177
var entries []JobCronEntry
175
- for _ , cron := range Crons {
176
- for _ , e := range cron .Entries () {
178
+ for entry := range Crons . IterBuffered () {
179
+ for _ , e := range entry . Val .Entries () {
177
180
entries = append (entries , toEntry (& e ))
178
181
}
179
182
}
0 commit comments