activejob 4.2.0.beta3 → 4.2.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_job/arguments.rb +6 -0
- data/lib/active_job/base.rb +46 -1
- data/lib/active_job/core.rb +2 -2
- data/lib/active_job/enqueuing.rb +1 -1
- data/lib/active_job/gem_version.rb +1 -1
- data/lib/active_job/logging.rb +1 -1
- data/lib/active_job/queue_adapter.rb +5 -2
- data/lib/active_job/queue_adapters.rb +3 -3
- data/lib/active_job/queue_adapters/inline_adapter.rb +1 -1
- data/lib/active_job/queue_adapters/qu_adapter.rb +2 -2
- data/lib/active_job/queue_adapters/queue_classic_adapter.rb +6 -6
- data/lib/active_job/queue_adapters/sidekiq_adapter.rb +3 -5
- data/lib/active_job/queue_name.rb +14 -2
- data/lib/active_job/test_helper.rb +2 -2
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7f0d0bb6e1251caa7d81084bb08533b08fad421
|
4
|
+
data.tar.gz: 68455756afb12ee46fd20d005339f53b429ffc06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad1b0d84c6ef53c2f1c9e0859d7dc1b4d1a08dd24f2eca11c181b433cfd318984216b63e9f32330f9bbabf5581a1e4c7f7d8dd897cebab16f40f3ab05a0c484c
|
7
|
+
data.tar.gz: af98007efc01844df75eade2e77443043f543a120fbdc58319aa95340bcec5f5a1fac82162d098dff3de90e7fc2d680192d4094d8d41663d9de6f7425912c2f9
|
data/lib/active_job/arguments.rb
CHANGED
@@ -24,10 +24,16 @@ module ActiveJob
|
|
24
24
|
extend self
|
25
25
|
TYPE_WHITELIST = [ NilClass, Fixnum, Float, String, TrueClass, FalseClass, Bignum ]
|
26
26
|
|
27
|
+
# Serializes a set of arguments. Whitelisted types are returned
|
28
|
+
# as-is. Arrays/Hashes are serialized element by element.
|
29
|
+
# All other types are serialized using GlobalID.
|
27
30
|
def serialize(arguments)
|
28
31
|
arguments.map { |argument| serialize_argument(argument) }
|
29
32
|
end
|
30
33
|
|
34
|
+
# Deserializes a set of arguments. Whitelisted types are returned
|
35
|
+
# as-is. Arrays/Hashes are deserialized element by element.
|
36
|
+
# All other types are deserialized using GlobalID.
|
31
37
|
def deserialize(arguments)
|
32
38
|
arguments.map { |argument| deserialize_argument(argument) }
|
33
39
|
rescue => e
|
data/lib/active_job/base.rb
CHANGED
@@ -6,7 +6,52 @@ require 'active_job/execution'
|
|
6
6
|
require 'active_job/callbacks'
|
7
7
|
require 'active_job/logging'
|
8
8
|
|
9
|
-
module ActiveJob
|
9
|
+
module ActiveJob #:nodoc:
|
10
|
+
# = Active Job
|
11
|
+
#
|
12
|
+
# Active Job objects can be configured to work with different backend
|
13
|
+
# queuing frameworks. To specify a queue adapter to use:
|
14
|
+
#
|
15
|
+
# ActiveJob::Base.queue_adapter = :inline
|
16
|
+
#
|
17
|
+
# A list of supported adapters can be found in QueueAdapters.
|
18
|
+
#
|
19
|
+
# Active Job objects can be defined by creating a class that inherits
|
20
|
+
# from the ActiveJob::Base class. The only necessary method to
|
21
|
+
# implement is the "perform" method.
|
22
|
+
#
|
23
|
+
# To define an Active Job object:
|
24
|
+
#
|
25
|
+
# class ProcessPhotoJob < ActiveJob::Base
|
26
|
+
# def perform(photo)
|
27
|
+
# photo.watermark!('Rails')
|
28
|
+
# photo.rotate!(90.degrees)
|
29
|
+
# photo.resize_to_fit!(300, 300)
|
30
|
+
# photo.upload!
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# Records that are passed in are serialized/deserialized using Global
|
35
|
+
# Id. More information can be found in Arguments.
|
36
|
+
#
|
37
|
+
# To enqueue a job to be performed as soon the queueing system is free:
|
38
|
+
#
|
39
|
+
# ProcessPhotoJob.perform_later(photo)
|
40
|
+
#
|
41
|
+
# To enqueue a job to be processed at some point in the future:
|
42
|
+
#
|
43
|
+
# ProcessPhotoJob.set(wait_until: Date.tomorrow.noon).perform_later(photo)
|
44
|
+
#
|
45
|
+
# More information can be found in ActiveJob::Core::ClassMethods#set
|
46
|
+
#
|
47
|
+
# A job can also be processed immediately without sending to the queue:
|
48
|
+
#
|
49
|
+
# ProcessPhotoJob.perform_now(photo)
|
50
|
+
#
|
51
|
+
# == Exceptions
|
52
|
+
#
|
53
|
+
# * DeserializationError - Error class for deserialization errors.
|
54
|
+
# * SerializationError - Error class for serialization errors.
|
10
55
|
class Base
|
11
56
|
include Core
|
12
57
|
include QueueAdapter
|
data/lib/active_job/core.rb
CHANGED
@@ -40,9 +40,9 @@ module ActiveJob
|
|
40
40
|
#
|
41
41
|
# VideoJob.set(queue: :some_queue).perform_later(Video.last)
|
42
42
|
# VideoJob.set(wait: 5.minutes).perform_later(Video.last)
|
43
|
-
# VideoJob.set(wait_until: Time.
|
43
|
+
# VideoJob.set(wait_until: Time.now.tomorrow).perform_later(Video.last)
|
44
44
|
# VideoJob.set(queue: :some_queue, wait: 5.minutes).perform_later(Video.last)
|
45
|
-
# VideoJob.set(queue: :some_queue, wait_until: Time.
|
45
|
+
# VideoJob.set(queue: :some_queue, wait_until: Time.now.tomorrow).perform_later(Video.last)
|
46
46
|
def set(options={})
|
47
47
|
ConfiguredJob.new(self, options)
|
48
48
|
end
|
data/lib/active_job/enqueuing.rb
CHANGED
@@ -10,7 +10,7 @@ module ActiveJob
|
|
10
10
|
# GlobalID::Identification instances. Arbitrary Ruby objects
|
11
11
|
# are not supported.
|
12
12
|
#
|
13
|
-
# Returns an instance of the job class queued with
|
13
|
+
# Returns an instance of the job class queued with arguments available in
|
14
14
|
# Job#arguments.
|
15
15
|
def perform_later(*args)
|
16
16
|
job_or_instantiate(*args).enqueue
|
data/lib/active_job/logging.rb
CHANGED
@@ -2,12 +2,15 @@ require 'active_job/queue_adapters/inline_adapter'
|
|
2
2
|
require 'active_support/core_ext/string/inflections'
|
3
3
|
|
4
4
|
module ActiveJob
|
5
|
-
module QueueAdapter
|
5
|
+
module QueueAdapter #:nodoc:
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
8
|
module ClassMethods
|
9
9
|
mattr_reader(:queue_adapter) { ActiveJob::QueueAdapters::InlineAdapter }
|
10
10
|
|
11
|
+
# Specify the backend queue provider. The default queue adapter
|
12
|
+
# is the :inline queue. See QueueAdapters for more
|
13
|
+
# information.
|
11
14
|
def queue_adapter=(name_or_adapter)
|
12
15
|
@@queue_adapter = \
|
13
16
|
case name_or_adapter
|
@@ -26,4 +29,4 @@ module ActiveJob
|
|
26
29
|
end
|
27
30
|
end
|
28
31
|
end
|
29
|
-
end
|
32
|
+
end
|
@@ -7,7 +7,7 @@ module ActiveJob
|
|
7
7
|
# * {Delayed Job}[https://github.com/collectiveidea/delayed_job]
|
8
8
|
# * {Qu}[https://github.com/bkeepers/qu]
|
9
9
|
# * {Que}[https://github.com/chanks/que]
|
10
|
-
# * {
|
10
|
+
# * {queue_classic}[https://github.com/QueueClassic/queue_classic]
|
11
11
|
# * {Resque 1.x}[https://github.com/resque/resque/tree/1-x-stable]
|
12
12
|
# * {Sidekiq}[http://sidekiq.org]
|
13
13
|
# * {Sneakers}[https://github.com/jondot/sneakers]
|
@@ -20,7 +20,7 @@ module ActiveJob
|
|
20
20
|
# | Backburner | Yes | Yes | Yes | Yes | Job | Global |
|
21
21
|
# | Delayed Job | Yes | Yes | Yes | Job | Global | Global |
|
22
22
|
# | Que | Yes | Yes | Yes | Job | No | Job |
|
23
|
-
# |
|
23
|
+
# | queue_classic | Yes | Yes | No* | No | No | No |
|
24
24
|
# | Resque | Yes | Yes | Yes (Gem) | Queue | Global | Yes |
|
25
25
|
# | Sidekiq | Yes | Yes | Yes | Queue | No | Job |
|
26
26
|
# | Sneakers | Yes | Yes | No | Queue | Queue | No |
|
@@ -29,7 +29,7 @@ module ActiveJob
|
|
29
29
|
# | Active Job | Yes | Yes | Yes | No | No | No |
|
30
30
|
#
|
31
31
|
# NOTE:
|
32
|
-
#
|
32
|
+
# queue_classic does not support Job scheduling. However you can implement this
|
33
33
|
# yourself or you can use the queue_classic-later gem. See the documentation for
|
34
34
|
# ActiveJob::QueueAdapters::QueueClassicAdapter.
|
35
35
|
#
|
@@ -15,7 +15,7 @@ module ActiveJob
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def enqueue_at(*) #:nodoc:
|
18
|
-
raise NotImplementedError.new("Use a queueing backend to enqueue jobs in the future. Read more at
|
18
|
+
raise NotImplementedError.new("Use a queueing backend to enqueue jobs in the future. Read more at http://guides.rubyonrails.org/v4.2.0/active_job_basics.html")
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -6,11 +6,11 @@ module ActiveJob
|
|
6
6
|
#
|
7
7
|
# Qu is a Ruby library for queuing and processing background jobs. It is
|
8
8
|
# heavily inspired by delayed_job and Resque. Qu was created to overcome
|
9
|
-
# some shortcomings in the existing queuing libraries
|
9
|
+
# some shortcomings in the existing queuing libraries.
|
10
10
|
# The advantages of Qu are: Multiple backends (redis, mongo), jobs are
|
11
11
|
# requeued when worker is killed, resque-like API.
|
12
12
|
#
|
13
|
-
# Read more about
|
13
|
+
# Read more about Qu {here}[https://github.com/bkeepers/qu].
|
14
14
|
#
|
15
15
|
# To use Qu set the queue_adapter config to +:qu+.
|
16
16
|
#
|
@@ -2,7 +2,7 @@ require 'queue_classic'
|
|
2
2
|
|
3
3
|
module ActiveJob
|
4
4
|
module QueueAdapters
|
5
|
-
# ==
|
5
|
+
# == queue_classic adapter for Active Job
|
6
6
|
#
|
7
7
|
# queue_classic provides a simple interface to a PostgreSQL-backed message
|
8
8
|
# queue. queue_classic specializes in concurrent locking and minimizing
|
@@ -11,9 +11,9 @@ module ActiveJob
|
|
11
11
|
# production environment and that adding another dependency (e.g. redis,
|
12
12
|
# beanstalkd, 0mq) is undesirable.
|
13
13
|
#
|
14
|
-
# Read more about
|
14
|
+
# Read more about queue_classic {here}[https://github.com/QueueClassic/queue_classic].
|
15
15
|
#
|
16
|
-
# To use
|
16
|
+
# To use queue_classic set the queue_adapter config to +:queue_classic+.
|
17
17
|
#
|
18
18
|
# Rails.application.config.active_job.queue_adapter = :queue_classic
|
19
19
|
class QueueClassicAdapter
|
@@ -25,8 +25,8 @@ module ActiveJob
|
|
25
25
|
def enqueue_at(job, timestamp) #:nodoc:
|
26
26
|
queue = build_queue(job.queue_name)
|
27
27
|
unless queue.respond_to?(:enqueue_at)
|
28
|
-
raise NotImplementedError, 'To be able to schedule jobs with
|
29
|
-
'the QC::Queue needs to respond to `enqueue_at(timestamp, method, *args)`. '
|
28
|
+
raise NotImplementedError, 'To be able to schedule jobs with queue_classic ' \
|
29
|
+
'the QC::Queue needs to respond to `enqueue_at(timestamp, method, *args)`. ' \
|
30
30
|
'You can implement this yourself or you can use the queue_classic-later gem.'
|
31
31
|
end
|
32
32
|
queue.enqueue_at(timestamp, "#{JobWrapper.name}.perform", job.serialize)
|
@@ -34,7 +34,7 @@ module ActiveJob
|
|
34
34
|
|
35
35
|
# Builds a <tt>QC::Queue</tt> object to schedule jobs on.
|
36
36
|
#
|
37
|
-
# If you have a custom <tt>QC::Queue</tt> subclass you'll need to
|
37
|
+
# If you have a custom <tt>QC::Queue</tt> subclass you'll need to subclass
|
38
38
|
# <tt>ActiveJob::QueueAdapters::QueueClassicAdapter</tt> and override the
|
39
39
|
# <tt>build_queue</tt> method.
|
40
40
|
def build_queue(queue_name)
|
@@ -6,8 +6,8 @@ module ActiveJob
|
|
6
6
|
#
|
7
7
|
# Simple, efficient background processing for Ruby. Sidekiq uses threads to
|
8
8
|
# handle many jobs at the same time in the same process. It does not
|
9
|
-
# require Rails but will integrate tightly with
|
10
|
-
#
|
9
|
+
# require Rails but will integrate tightly with it to make background
|
10
|
+
# processing dead simple.
|
11
11
|
#
|
12
12
|
# Read more about Sidekiq {here}[http://sidekiq.org].
|
13
13
|
#
|
@@ -21,8 +21,7 @@ module ActiveJob
|
|
21
21
|
Sidekiq::Client.push \
|
22
22
|
'class' => JobWrapper,
|
23
23
|
'queue' => job.queue_name,
|
24
|
-
'args' => [ job.serialize ]
|
25
|
-
'retry' => true
|
24
|
+
'args' => [ job.serialize ]
|
26
25
|
end
|
27
26
|
|
28
27
|
def enqueue_at(job, timestamp) #:nodoc:
|
@@ -30,7 +29,6 @@ module ActiveJob
|
|
30
29
|
'class' => JobWrapper,
|
31
30
|
'queue' => job.queue_name,
|
32
31
|
'args' => [ job.serialize ],
|
33
|
-
'retry' => true,
|
34
32
|
'at' => timestamp
|
35
33
|
end
|
36
34
|
end
|
@@ -6,6 +6,15 @@ module ActiveJob
|
|
6
6
|
mattr_accessor(:queue_name_prefix)
|
7
7
|
mattr_accessor(:default_queue_name) { "default" }
|
8
8
|
|
9
|
+
# Specifies the name of the queue to process the job on.
|
10
|
+
#
|
11
|
+
# class PublishToFeedJob < ActiveJob::Base
|
12
|
+
# queue_as :feeds
|
13
|
+
#
|
14
|
+
# def perform(post)
|
15
|
+
# post.to_feed!
|
16
|
+
# end
|
17
|
+
# end
|
9
18
|
def queue_as(part_name=nil, &block)
|
10
19
|
if block_given?
|
11
20
|
self.queue_name = block
|
@@ -15,15 +24,18 @@ module ActiveJob
|
|
15
24
|
end
|
16
25
|
|
17
26
|
def queue_name_from_part(part_name) #:nodoc:
|
18
|
-
queue_name = part_name
|
27
|
+
queue_name = part_name || default_queue_name
|
19
28
|
name_parts = [queue_name_prefix.presence, queue_name]
|
20
|
-
name_parts.compact.join(
|
29
|
+
name_parts.compact.join(queue_name_delimiter)
|
21
30
|
end
|
22
31
|
end
|
23
32
|
|
24
33
|
included do
|
25
34
|
class_attribute :queue_name, instance_accessor: false
|
35
|
+
class_attribute :queue_name_delimiter, instance_accessor: false
|
36
|
+
|
26
37
|
self.queue_name = default_queue_name
|
38
|
+
self.queue_name_delimiter = '_' # set default delimiter to '_'
|
27
39
|
end
|
28
40
|
|
29
41
|
# Returns the name of the queue the job will be run on
|
@@ -71,7 +71,7 @@ module ActiveJob
|
|
71
71
|
#
|
72
72
|
# Note: This assertion is simply a shortcut for:
|
73
73
|
#
|
74
|
-
# assert_enqueued_jobs 0
|
74
|
+
# assert_enqueued_jobs 0, &block
|
75
75
|
def assert_no_enqueued_jobs(&block)
|
76
76
|
assert_enqueued_jobs 0, &block
|
77
77
|
end
|
@@ -130,7 +130,7 @@ module ActiveJob
|
|
130
130
|
#
|
131
131
|
# Note: This assertion is simply a shortcut for:
|
132
132
|
#
|
133
|
-
# assert_performed_jobs 0
|
133
|
+
# assert_performed_jobs 0, &block
|
134
134
|
def assert_no_performed_jobs(&block)
|
135
135
|
assert_performed_jobs 0, &block
|
136
136
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activejob
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.2.0.
|
4
|
+
version: 4.2.0.beta4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,26 +16,26 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.2.0.
|
19
|
+
version: 4.2.0.beta4
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 4.2.0.
|
26
|
+
version: 4.2.0.beta4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: globalid
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.3.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.3.0
|
41
41
|
description: Declare job classes that can be run by a variety of queueing backends.
|
@@ -87,17 +87,17 @@ require_paths:
|
|
87
87
|
- lib
|
88
88
|
required_ruby_version: !ruby/object:Gem::Requirement
|
89
89
|
requirements:
|
90
|
-
- -
|
90
|
+
- - '>='
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: 1.9.3
|
93
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- -
|
95
|
+
- - '>'
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: 1.3.1
|
98
98
|
requirements: []
|
99
99
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.2.
|
100
|
+
rubygems_version: 2.2.1
|
101
101
|
signing_key:
|
102
102
|
specification_version: 4
|
103
103
|
summary: Job framework with pluggable queues.
|