-
Notifications
You must be signed in to change notification settings - Fork 74
Scheduled tasks
There are several alternatives out there for you to run a scheduled task in your app. It can be as low level as setting up a crontab in EC2, or as high level as installing the Heroku Scheduler add-on to your app.
But sometimes you need more. Maybe you're not able to change your tasks the way you want, maybe you need more control and introspection around task execution, maybe you want to test the whole thing... When this time arrives, we suggest bringing the scheduling to your app with Clockwork.
To illustrate, lets add a scheduled task to measure the background worker queue in a Pliny app.
Start adding Clockwork to the Gemfile:
gem 'clockwork'
Then define a task in lib/clock.rb
:
require 'clockwork'
require_relative 'application'
module Clockwork
every(10.seconds, 'monitor_queue') do
queue_stats = MyBackgroundWorkerLibrary.stats
Pliny.log(queue_stats)
end
end
And add a clock entry to your Procfile
:
clock: bundle exec clockwork lib/clock.rb
Now you can run your clock process locally like:
foreman start clock
Further reading:
Basics
Diving in
- bin/setup
- Config
- CORS
- Endpoints
- Error Handling
- Logging
- Models
- Mediators
- Migrations
- Rake Tasks
- Request IDs
- RequestStore
- Schema
- Serialization
- Testing
- Updating
Guides