Skip to content

urbanladder/melinis

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Melinis

Melinis is library for managing background jobs like Rake tasks, cron jobs etc. that do some kind of batch processing.

Installation

To install Melinis, add it to your Gemfile

gem 'melinis', github: 'urbanladder/melinis'

In your rails application, run

db:migrate

Usage

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

Example

Rake Task:

task :test_task => :environment do |task|
  mt = MyTask.new.run
end

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 90.0%
  • JavaScript 4.3%
  • CSS 3.9%
  • HTML 1.8%