Skip to content

docs: add cookbook/recipes documentation #204

@CybotTM

Description

@CybotTM

Description

Users would benefit from a cookbook showing common patterns and best practices.

Missing Recipes

  1. Basic Setup: Simple scheduler with logging
  2. Retry Pattern: External API calls with retry
  3. Circuit Breaker: Protecting failing services
  4. Metrics Integration: Prometheus/StatsD examples
  5. Graceful Shutdown: Kubernetes-style termination
  6. Testing Jobs: Unit testing job functions
  7. Dynamic Scheduling: Adding/removing jobs at runtime
  8. 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/Gemini

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationgood first issueGood for newcomers

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions