Project

ost-job

0.0
No commit activity in last 3 years
No release in over 3 years
Job base classes for Ost
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.2
 Project Readme

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