Skip to content

This gem allows you to write async processing code to your models right into your models code

License

Notifications You must be signed in to change notification settings

dobryakov/acts_as_backdrop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

acts_as_backdrop

This gem allows you to write async processing code to your models right into your models code.

Build Status Gem Version Dependency Status Code Climate

Example

class Something < ActiveRecord::Base
  acts_as_backdrop

  def backdrop_process(message)

    # This method will be processed asyncronously after model save.
    # You receive complete info about model changes, and may process it as you wish:
    #
    # {
    #   "class"   => "Something",
    #   "gid"     => "gid://dummy/Something/1",
    #   "changes" => {
    #     "title"       => ["old title", "new title"],
    #     "description" => [nil, "very long description"]
    #   }
    # }

  end

end

Why

Because you might need to process some data after the model is saved, asynchronously.

Installation

gem 'act_as_backdrop' # Gemfile
require 'backdrop'    # application.rb

How it works

When your model instance saved (on after_commit callback), the model itself and it's changes published to async job queue as usual DelayedJob. The special worker (BackdropJob class) will process this message and will trigger your 'backdrop_process' method inside your model.

You receive full information about model changes, and can process it as you wish. If you change the model state at this step, the next async task will happen and be processed in same way.

History

0.0.4: changed from 'after_save' to 'after_commit'.

About

This gem allows you to write async processing code to your models right into your models code

Resources

License

Stars

Watchers

Forks

Packages

No packages published