[ActiveJob] Use globalid gem

This commit is contained in:
Abdelkader Boudih 2014-08-17 01:06:30 +00:00
parent 59221cc4f1
commit 2f7b239fca
9 changed files with 11 additions and 14 deletions

View File

@ -36,6 +36,7 @@ end
gem 'dalli', '>= 2.2.1'
# ActiveJob
gem 'globalid', github: 'rails/globalid'
gem 'resque', require: false
gem 'resque-scheduler', require: false
gem 'sidekiq', require: false

View File

@ -4,7 +4,6 @@ require 'set'
require 'action_dispatch'
require 'active_support/time'
require 'active_support/core_ext/object/itself'
require 'mailers/base_mailer'
require 'mailers/proc_mailer'

View File

@ -59,7 +59,7 @@ That's it!
## GlobalID support
Active Job supports [GlobalID serialization](https://github.com/rails/activemodel-globalid/) for parameters. This makes it possible
Active Job supports [GlobalID serialization](https://github.com/rails/globalid/) for parameters. This makes it possible
to pass live Active Record objects to your job instead of class/id pairs, which
you then have to manually deserialize. Before, jobs would look like this:
@ -82,7 +82,7 @@ class TrashableCleanupJob
end
```
This works with any class that mixes in ActiveModel::GlobalIdentification, which
This works with any class that mixes in GlobalID::Identification, which
by default has been mixed into Active Record classes.

View File

@ -18,6 +18,5 @@ Gem::Specification.new do |s|
s.files = Dir['CHANGELOG.md', 'MIT-LICENSE', 'README.md', 'lib/**/*']
s.require_path = 'lib'
s.add_dependency 'activesupport', version
s.add_dependency 'activemodel-globalid'
s.add_dependency 'globalid'
end

View File

@ -24,6 +24,7 @@
require 'active_support'
require 'active_support/rails'
require 'active_job/version'
require 'global_id'
module ActiveJob
extend ActiveSupport::Autoload

View File

@ -1,6 +1,3 @@
require 'active_model/global_locator'
require 'active_model/global_identification'
module ActiveJob
module Arguments
extend self
@ -17,7 +14,7 @@ module ActiveJob
private
def serialize_argument(argument)
case argument
when ActiveModel::GlobalIdentification
when GlobalID::Identification
argument.global_id.to_s
when *TYPE_WHITELIST
argument
@ -37,7 +34,7 @@ module ActiveJob
when Hash
Hash[ argument.map { |key, value| [ key, deserialize_argument(value) ] } ].with_indifferent_access
else
ActiveModel::GlobalLocator.locate(argument) || argument
GlobalID::Locator.locate(argument) || argument
end
end

View File

@ -7,7 +7,7 @@ module ActiveJob
module ClassMethods
# Push a job onto the queue. The arguments must be legal JSON types
# (string, int, float, nil, true, false, hash or array) or
# ActiveModel::GlobalIdentication instances. Arbitrary Ruby objects
# GlobalID::Identification instances. Arbitrary Ruby objects
# are not supported.
#
# Returns an instance of the job class queued with args available in

View File

@ -2,6 +2,8 @@ require File.expand_path('../../../load_paths', __FILE__)
require 'active_job'
GlobalID.app = 'aj'
@adapter = ENV['AJADAPTER'] || 'inline'
def sidekiq?

View File

@ -1,7 +1,5 @@
require 'active_model/global_identification'
class Person
include ActiveModel::GlobalIdentification
include GlobalID::Identification
attr_reader :id