How to use ActiveJob with Rails 4.1?

For reasons (ActiveAdmin), I currently cannot use Rails 4.2 in a new project.

However, the ActiveJob function looks like a good abstraction, so I would like to use it if possible.

Does anyone have any experience with Rails 4.1?

+5
source share
1 answer

UPDATE

Now there is a better solution :), try this gem activejob_backport , it is easier to install, the same functions as rails 4.2.


CAUTION: OUTSIDE CONTENTS BELOW

To use ActiveJob in Rails 4.1, you need to do this first.

# in Gemfile gem 'activejob' # in your terminal bundle # create a config/initializers/active_job.rb require 'active_job' # or any other supported backend such as :sidekiq or :delayed_job ActiveJob::Base.queue_adapter = :inline 

You should then be able to reference ActiveJob in your rails application to create and queue a job:

 # app/jobs/guests_cleanup_job.rb class GuestsCleanupJob < ActiveJob::Base queue_as :default def perform(*args) # Do something later end end # usage GuestsCleanupJob.enqueue(record) GuestsCleanupJob.enqueue(record, options) 

However, there are some errors: the big difference is not exactly the same ActiveJob inside Rails 4.2.beta strong>, as the flaws of the generators, callbacks and syntax are slightly different. I wrote a blog post if you want to dig more: http://kinopyo.com/blog/use-activejob-in-rails-4-1/

+3
source

Source: https://habr.com/ru/post/1205026/


All Articles