Melinis is library for managing background jobs like Rake tasks, cron jobs etc. that do some kind of batch processing.
To install Melinis, add it to your Gemfile
gem 'melinis', github: 'urbanladder/melinis'
In your rails application, run
db:migrate
Subclass Melinis::Task & override the following methods:
1. prepare
2. execute
3. execution_failure
4. wrapup
class MyTask < Melinis::Task
def initialize
super('MyTask', {
:description => 'Details here',
:file_path => './my_task.rb',
:command => '',
:individual_retries_limit => 0,
:bulk_retries_limit => 0
})
// Other custom initialization here
end
def prepare
data = last_run.data
// Use 'data' to figure out what needs to be done in this run.
// Return an array of items to be processed
10.times.map { 10 * Random.rand(11) }
end
def execute(unit)
// Each item in the array returned by `prepare` is passed as a parameter
// to the `execute` method.
1000 / unit
end
def execution_failure(unit)
{:id => unit}
end
def wrapup
{}
end
end
task :test_task => :environment do |task| mt = MyTask.new.run end