A simple example demonstrating how to use Sentry Crons monitoring with Sidekiq-Cron, a popular cron scheduler for Sidekiq background jobs.
- Runs a heartbeat job every minute using Sidekiq-Cron
- Automatic Sentry cron monitoring integration
- Uses Redis for job persistence
- Docker Compose setup for easy deployment
- Docker and Docker Compose
- Or: Ruby 3.0+, Redis server
-
Clone and navigate to this example:
cd ruby/sidekiq-cron -
Configure Sentry:
cp .env.example .env
Then edit
.envand set your actual Sentry DSN:SENTRY_DSN=https://your-actual-dsn@o0.ingest.sentry.io/0 SENTRY_ENVIRONMENT=development -
Start the services:
docker-compose up
-
View logs:
docker-compose logs -f sidekiq
-
Stop services:
docker-compose down
If you already have Redis running elsewhere:
-
Build the image:
docker build -t ruby-sidekiq-cron-example . -
Run with environment variables:
docker run -d --name sidekiq-cron-app \ -e SENTRY_DSN="your-dsn-here" \ -e SENTRY_ENVIRONMENT="production" \ -e REDIS_URL="redis://your-redis-host:6379/0" \ ruby-sidekiq-cron-example
Sidekiq-Cron extends Sidekiq with cron-like scheduling capabilities:
- Schedule Definition: Jobs are defined in
config/schedule.ymlwith cron syntax - Job Loading: On startup, Sidekiq loads the schedule and creates recurring jobs
- Execution: Sidekiq-Cron checks every 30 seconds for jobs to enqueue
- Monitoring: Sentry automatically tracks each job execution
The example includes:
- A
HeartbeatWorkerthat runs every minute - Automatic Sentry check-in monitoring via the
enabled_patchesconfiguration - Redis for storing job schedules and queues
- Docker Compose for easy local development
This example uses automatic Sentry monitoring through the enabled_patches configuration:
config.enabled_patches += [:sidekiq_cron]This automatically:
- Creates/updates monitors in Sentry when jobs run
- Sends check-in events (in_progress, ok, error)
- Captures any exceptions during job execution
- Monitors based on the cron schedule defined in
schedule.yml
- Redis: Stores job queues and cron schedules
- Sidekiq: Processes background jobs
- Sidekiq-Cron: Adds cron scheduling to Sidekiq
- Sentry: Monitors job execution and errors