bemurphy / ost-job

Job base classes for Ost

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ost::Job

Job base classes for Ost and ost-bin.

Description

Ost provides simple, lightweight background job functionality. By default, it assumes you are passing very primative ids like a numeric user id to the queue.

Ost::Job and Ost::JsonJob provide a super thin interface to a job class that plays nice with ost-bin.

Installation

$ gem install ost-job

Usage

Setup your Ostfile as specified by ost-bin.

Declare a job class with a #perform instance method.

For a regular job that is passed a single id or string:

class Plain < Ost::Job
  def perform(user_id)
    user = User.find(user_id)
    # do something with user
  end
end

If you want to pass richer data to your job, inherit Ost::JsonJob

# Enqueue the job
Ost[:Mailer] << {user_id: 42, subject: 'Hello', body: 'World'}.to_json

# Declare your Job Class
class Mailer < Ost::JsonJob
  def perform(data)
    user = User.find(data['user_id'])
    Mail.deliver(user: user, subject: data['subject'], body: data['body'])
  end
end

About

Job base classes for Ost

License:MIT License


Languages

Language:Ruby 100.0%