-
Notifications
You must be signed in to change notification settings - Fork 73
Scheduled tasks
There are several alternatives out there allowing developers to schedule the execution of tasks.
They 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; either way, the basic idea is to have something outside your app triggering a custom rake task periodically.
If you need some kind of flexibility, accuracy or guarantee that your scheduling service cannot provide, there is always the option to handle scheduling within your app.
For Pliny we recommend in-app scheduling 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
Basics
Diving in
- bin/setup
- Config
- CORS
- Endpoints
- Error Handling
- Logging
- Models
- Mediators
- Migrations
- Rake Tasks
- Request IDs
- RequestStore
- Schema
- Serialization
- Testing
- Updating
Guides