forked from robfig/cron
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationgood first issueGood for newcomersGood for newcomers
Description
Description
Users would benefit from a cookbook showing common patterns and best practices.
Missing Recipes
- Basic Setup: Simple scheduler with logging
- Retry Pattern: External API calls with retry
- Circuit Breaker: Protecting failing services
- Metrics Integration: Prometheus/StatsD examples
- Graceful Shutdown: Kubernetes-style termination
- Testing Jobs: Unit testing job functions
- Dynamic Scheduling: Adding/removing jobs at runtime
- Multi-Timezone: Handling jobs in different timezones
Example Recipe
# Recipe: Retry Pattern for External APIs
Problem: You need to call an external API that occasionally fails.
Solution:
\`\`\`go
c := cron.New(
cron.WithChain(
cron.Recover(logger),
cron.RetryWithBackoff(logger, 3, time.Second, time.Minute, 2.0),
),
)
c.AddFunc("@every 5m", func() {
resp, err := http.Get("https://api.example.com/data")
if err != nil {
panic(err) // Will trigger retry
}
defer resp.Body.Close()
// Process response...
})
\`\`\`
Key Points:
- Retry wraps the job, catching panics
- Exponential backoff prevents thundering herd
- Recover ensures scheduler continues if retries exhaust
\`\`\`
## Severity
🟢 **Low** - Documentation for adoption
## Found By
Pre-1.0 release code review with Zen/GeminiMetadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationgood first issueGood for newcomersGood for newcomers