k-akarsh / melinis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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: 'k-akarsh/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

License:MIT License


Languages

Language:Ruby 89.7%Language:JavaScript 4.4%Language:CSS 4.0%Language:HTML 1.8%