AI Decision System
Replayable, offline-verifiable records for AI-assisted go/no-go decisions: experiment promotions, typed model answers and human-approved actions.
翻譯準備中
Easy and fluent Go cron scheduling. This is a fork from https://github.com/jasonlvhit/gocron
翻譯準備中
開發工具Go · MakefileGitHub @go-co-op自行安裝營運者未確認
試用過了嗎? 點一下就好,不需要登入。
製作者的介紹僅有上面的一句話。 更多詳情請閱讀儲存庫 README。 儲存庫 README ↗
正在載入完整 README。
檢視完整 README ↗gocron is a job scheduling package which lets you run Go functions at pre-determined intervals.
Looking for a visual interface? Check out gocron-ui — a lightweight web dashboard to monitor, trigger, and manage your
gocronjobs in real time.
If you want to chat, you can find us on Slack at
go get github.com/go-co-op/gocron/v2
package main
import (
"fmt"
"time"
"github.com/go-co-op/gocron/v2"
)
func main() {
// create a scheduler
s, err := gocron.NewScheduler()
if err != nil {
// handle error
}
// add a job to the scheduler
j, err := s.NewJob(
gocron.DurationJob(
10*time.Second,
),
gocron.NewTask(
func(a string, b int) {
// do things
},
"hello",
1,
),
)
if err != nil {
// handle error
}
// each job has a unique id
fmt.Println(j.ID())
// start the scheduler
s.Start()
// block until you are ready to shut down
select {
case <-time.After(time.Minute):
}
// when you're done, shut it down
err = s.Shutdown()
// or for context-aware teardown:
// err = s.ShutdownWithContext(ctx)
if err != nil {
// handle error
}
}
Community articles and tutorials about using gocron:
Jobs can be run at various intervals.
time.Duration.time.Duration between a min and max.Jobs can be scheduled with different interval timing modes.
Jobs can be limited individually or across the entire scheduler.
Multiple instances of gocron can be run.
Job events can trigger actions.
Many job and scheduler options are available.
NewJob.NewScheduler
and the WithGlobalJobOptions option.NewScheduler.Logs can be enabled.
Metrics may be collected from the execution of each job and scheduler lifecycle events.
Monitor: A monitor can be used to collect metrics for each job from a scheduler.
MonitorStatus: Extends Monitor with status and error tracking for each job.
SchedulerMonitor: A scheduler monitor provides comprehensive observability into scheduler and job lifecycle events.
Available Metrics:
SchedulerStarted, SchedulerStopped, SchedulerShutdownJobRegistered, JobUnregistered - track jobs added/removed from schedulerJobStarted, JobRunning, JobCompleted, JobFailed - monitor job execution flowJobExecutionTime, JobSchedulingDelay - measure job duration and scheduling lagThe gocron library is set up to enable testing.
We appreciate the support for free and open source software!
This project is supported by:
ConcurrencyLimitReachedDerived Metrics (calculable from events):
JobFailed / (JobCompleted + JobFailed)JobExecutionTime eventsJobRegistered - JobUnregisteredJobStarted - (JobCompleted + JobFailed)Example - Prometheus Integration:
type PrometheusMonitor struct {
jobsCompleted prometheus.Counter
jobsFailed prometheus.Counter
executionTime prometheus.Histogram
schedulingDelay prometheus.Histogram
}
func (p *PrometheusMonitor) JobExecutionTime(job gocron.Job, duration time.Duration) {
p.executionTime.Observe(duration.Seconds())
}
func (p *PrometheusMonitor) JobSchedulingDelay(job gocron.Job, scheduled, actual time.Time) {
if delay := actual.Sub(scheduled); delay > 0 {
p.schedulingDelay.Observe(delay.Seconds())
}
}
// Initialize scheduler with monitor
s, _ := gocron.NewScheduler(gocron.WithSchedulerMonitor(monitor))
Use Cases: Prometheus metrics, custom dashboards, alerting systems, performance monitoring