No release in over 3 years
Low commit activity in last 3 years
This gem has been renamed active_model_jobs.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0.49.0
>= 0.9.20

Runtime

>= 5.0.0
>= 5.0.0
 Project Readme

ActiveModel::Jobs

Build Status Code Climate Test Coverage Inline docs

A model-level interface for kicking off background jobs using ActiveJob. Most useful inside a Rails application, it enables you to enqueue ActiveJob jobs with a dynamically-generated instance method inside your ActiveRecord (or ActiveModel-compatible) model class.

Documentation

Installation

Add this line to your application's Gemfile:

gem 'active_model-jobs'

And then run:

$ bundle

If you're using ActiveRecord, the ActiveModel::Jobs module will be included in your models by default. For other ORMs or POROs that use ActiveModel, you'll need to include the module yourself:

class Model
  include ActiveModel::Model
  include ActiveModel::Jobs
end

Usage

Given we already have a model called Track, generate a job called UploadTrackJob:

require 'aws/s3'

class UploadTrackJob < ActiveRecord::Base
  queue_as :default

  def perform(track)
    s3.put_object(track.file.data, track.file.attributes)
  end

  private

  def s3
    AWS::S3.new
  end
end

Now, you can kick off that job by calling its "action method" on your model:

class Track < ActiveRecord::Base
  attachment :file

  after_create :upload!
end

Since this is just an instance method, you can call track.upload! to kick off the job at any time outside of the callback lifecycle.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bin/console for an interactive prompt that will allow you to experiment.

We follow a semantic versioning guideline when releasing new versions. Documentation updates do not get a new version, it is just merged into 'master' and updated on http://rubydoc.info.

Contributing

  1. Fork it ( https://github.com/tubbo/active_model-jobs/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

All contributions must be made in a pull request and include accompanying tests. Pull requests will not be merged until they pass the CI build for all supported Ruby and Rails versions. To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release to create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Also see our Code of Conduct.