activejob 0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +1 -0
- data/MIT-LICENSE +21 -0
- data/lib/active_job.rb +33 -0
- data/lib/active_job/base.rb +13 -0
- data/lib/active_job/enqueuing.rb +18 -0
- data/lib/active_job/gem_version.rb +15 -0
- data/lib/active_job/log_subscriber.rb +19 -0
- data/lib/active_job/logging.rb +7 -0
- data/lib/active_job/parameters.rb +19 -0
- data/lib/active_job/queue_adapter.rb +24 -0
- data/lib/active_job/queue_adapters/backburner_adapter.rb +21 -0
- data/lib/active_job/queue_adapters/delayed_job_adapter.rb +19 -0
- data/lib/active_job/queue_adapters/inline_adapter.rb +11 -0
- data/lib/active_job/queue_adapters/que_adapter.rb +19 -0
- data/lib/active_job/queue_adapters/queue_classic_adapter.rb +19 -0
- data/lib/active_job/queue_adapters/resque_adapter.rb +31 -0
- data/lib/active_job/queue_adapters/sidekiq_adapter.rb +25 -0
- data/lib/active_job/queue_adapters/sneakers_adapter.rb +27 -0
- data/lib/active_job/queue_adapters/sucker_punch_adapter.rb +21 -0
- data/lib/active_job/queue_name.rb +10 -0
- data/lib/active_job/railitie.rb +8 -0
- data/lib/active_job/version.rb +8 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ed055b7c1ce137d0b117867a22ba1ba004b74cbf
|
4
|
+
data.tar.gz: ea42dac65bcb13b4cc7b1897604c1f3b105c41ac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 14b4bf2e84d31918d860f075dcd556f494de8ef35e52ba4b864c3f7e5fbe9cd30470f89851b2d36a1a993a929de0c56b0693cac5833660b0d0393bfdcdc5eb97
|
7
|
+
data.tar.gz: cbf00f328f8149a6e52dc757c362cd46399b5931ef389e959a58b6e79c5e5581f75d2b4937cf3547cb8e4994e38674e9bf7dd65649f7ac25069da25eeb3e6851
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* Started project.
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2014 David Heinemeier Hansson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/lib/active_job.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2014 David Heinemeier Hansson
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
require 'active_support'
|
25
|
+
require 'active_support/rails'
|
26
|
+
|
27
|
+
require 'active_job/version'
|
28
|
+
|
29
|
+
module ActiveJob
|
30
|
+
extend ActiveSupport::Autoload
|
31
|
+
|
32
|
+
autoload :Base
|
33
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'active_job/queue_adapter'
|
2
|
+
require 'active_job/queue_name'
|
3
|
+
require 'active_job/enqueuing'
|
4
|
+
require 'active_job/logging'
|
5
|
+
|
6
|
+
module ActiveJob
|
7
|
+
class Base
|
8
|
+
extend QueueAdapter
|
9
|
+
extend QueueName
|
10
|
+
extend Enqueuing
|
11
|
+
extend Logging
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'active_job/parameters'
|
2
|
+
|
3
|
+
module ActiveJob
|
4
|
+
module Enqueuing
|
5
|
+
# Push a job onto the queue. The arguments must be legal JSON types
|
6
|
+
# (string, int, float, nil, true, false, hash or array) or
|
7
|
+
# ActiveModel::GlobalIdentication instances. Arbitrary Ruby objects
|
8
|
+
# are not supported.
|
9
|
+
#
|
10
|
+
# The return value is adapter-specific and may change in a future
|
11
|
+
# ActiveJob release.
|
12
|
+
def enqueue(*args)
|
13
|
+
serialized_args = Parameters.serialize(args)
|
14
|
+
ActiveSupport::Notifications.instrument "enqueue.active_job", adapter: queue_adapter, job: self, args: serialized_args
|
15
|
+
queue_adapter.queue self, *serialized_args
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActiveJob
|
2
|
+
# Returns the version of the currently loaded ActiveJob as a <tt>Gem::Version</tt>
|
3
|
+
def self.gem_version
|
4
|
+
Gem::Version.new VERSION::STRING
|
5
|
+
end
|
6
|
+
|
7
|
+
module VERSION
|
8
|
+
MAJOR = 4
|
9
|
+
MINOR = 2
|
10
|
+
TINY = 0
|
11
|
+
PRE = "alpha"
|
12
|
+
|
13
|
+
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'active_support/core_ext/string/filters'
|
2
|
+
|
3
|
+
module ActiveJob
|
4
|
+
class LogSubscriber < ActiveSupport::LogSubscriber
|
5
|
+
def enqueue(event)
|
6
|
+
queue_name = event.payload[:adapter].name.demodulize.remove('Adapter')
|
7
|
+
job_name = event.payload[:job].name
|
8
|
+
args = event.payload[:args].any? ? ": #{event.payload[:args].inspect}" : ""
|
9
|
+
|
10
|
+
info "Enqueued #{job_name} to #{queue_name}" + args
|
11
|
+
end
|
12
|
+
|
13
|
+
def logger
|
14
|
+
ActiveJob::Base.logger
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
ActiveJob::LogSubscriber.attach_to :active_job
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'active_model/global_locator'
|
2
|
+
require 'active_support/core_ext/object/try'
|
3
|
+
|
4
|
+
module ActiveJob
|
5
|
+
class Parameters
|
6
|
+
TYPE_WHITELIST = [NilClass, Fixnum, Float, String, TrueClass, FalseClass, Hash, Array, Bignum]
|
7
|
+
|
8
|
+
def self.serialize(params)
|
9
|
+
params.collect do |param|
|
10
|
+
raise "Unsupported parameter type: #{param.class.name}" unless param.respond_to?(:global_id) || TYPE_WHITELIST.include?(param.class)
|
11
|
+
param.try(:global_id) || param
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.deserialize(params)
|
16
|
+
params.collect { |param| ActiveModel::GlobalLocator.locate(param) || param }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'active_job/queue_adapters/inline_adapter'
|
2
|
+
require 'active_support/core_ext/string/inflections'
|
3
|
+
|
4
|
+
module ActiveJob
|
5
|
+
module QueueAdapter
|
6
|
+
mattr_reader(:queue_adapter) { ActiveJob::QueueAdapters::InlineAdapter }
|
7
|
+
|
8
|
+
def queue_adapter=(name_or_adapter)
|
9
|
+
@@queue_adapter = \
|
10
|
+
case name_or_adapter
|
11
|
+
when Symbol, String
|
12
|
+
load_adapter(name_or_adapter)
|
13
|
+
when Class
|
14
|
+
name_or_adapter
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def load_adapter(name)
|
20
|
+
require "active_job/queue_adapters/#{name}_adapter"
|
21
|
+
"ActiveJob::QueueAdapters::#{name.to_s.camelize}Adapter".constantize
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'backburner'
|
2
|
+
|
3
|
+
module ActiveJob
|
4
|
+
module QueueAdapters
|
5
|
+
class BackburnerAdapter
|
6
|
+
class << self
|
7
|
+
def queue(job, *args)
|
8
|
+
Backburner::Worker.enqueue JobWrapper, [ job.name, *args ], queue: job.queue_name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class JobWrapper
|
13
|
+
class << self
|
14
|
+
def perform(job_name, *args)
|
15
|
+
job_name.constantize.new.perform *Parameters.deserialize(args)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'delayed_job'
|
2
|
+
|
3
|
+
module ActiveJob
|
4
|
+
module QueueAdapters
|
5
|
+
class DelayedJobAdapter
|
6
|
+
class << self
|
7
|
+
def queue(job, *args)
|
8
|
+
JobWrapper.new.delay(queue: job.queue_name).perform(job, *args)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class JobWrapper
|
13
|
+
def perform(job, *args)
|
14
|
+
job.new.perform *Parameters.deserialize(args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'que'
|
2
|
+
|
3
|
+
module ActiveJob
|
4
|
+
module QueueAdapters
|
5
|
+
class QueAdapter
|
6
|
+
class << self
|
7
|
+
def queue(job, *args)
|
8
|
+
JobWrapper.enqueue job, *args, queue: job.queue_name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class JobWrapper < Que::Job
|
13
|
+
def run(job, *args)
|
14
|
+
job.new.perform *Parameters.deserialize(args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'queue_classic'
|
2
|
+
|
3
|
+
module ActiveJob
|
4
|
+
module QueueAdapters
|
5
|
+
class QueueClassicAdapter
|
6
|
+
class << self
|
7
|
+
def queue(job, *args)
|
8
|
+
QC::Queue.new(job.queue_name).enqueue("#{JobWrapper.name}.perform", job, *args)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class JobWrapper
|
13
|
+
def self.perform(job, *args)
|
14
|
+
job.new.perform *Parameters.deserialize(args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'resque'
|
2
|
+
require 'active_support/core_ext/enumerable'
|
3
|
+
require 'active_support/core_ext/array/access'
|
4
|
+
|
5
|
+
module ActiveJob
|
6
|
+
module QueueAdapters
|
7
|
+
class ResqueAdapter
|
8
|
+
class << self
|
9
|
+
def queue(job, *args)
|
10
|
+
Resque.enqueue JobWrapper.new(job), job, *args
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class JobWrapper
|
15
|
+
class << self
|
16
|
+
def perform(job_name, *args)
|
17
|
+
job_name.constantize.new.perform *Parameters.deserialize(args)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(job)
|
22
|
+
@queue = job.queue_name
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
self.class.name
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'sidekiq'
|
2
|
+
|
3
|
+
module ActiveJob
|
4
|
+
module QueueAdapters
|
5
|
+
class SidekiqAdapter
|
6
|
+
class << self
|
7
|
+
def queue(job, *args)
|
8
|
+
Sidekiq::Client.push \
|
9
|
+
'class' => JobWrapper,
|
10
|
+
'queue' => job.queue_name,
|
11
|
+
'args' => [ job, *args ],
|
12
|
+
'retry' => true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class JobWrapper
|
17
|
+
include Sidekiq::Worker
|
18
|
+
|
19
|
+
def perform(job_name, *args)
|
20
|
+
job_name.constantize.new.perform *Parameters.deserialize(args)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'sneakers'
|
2
|
+
require 'thread'
|
3
|
+
|
4
|
+
module ActiveJob
|
5
|
+
module QueueAdapters
|
6
|
+
class SneakersAdapter
|
7
|
+
@mutex = Mutex.new
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def queue(job, *args)
|
11
|
+
@mutex.synchronize do
|
12
|
+
JobWrapper.from_queue job.queue_name
|
13
|
+
JobWrapper.enqueue [ job, *args ]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class JobWrapper
|
19
|
+
include Sneakers::Worker
|
20
|
+
|
21
|
+
def work(job, *args)
|
22
|
+
job.new.perform *Parameters.deserialize(args)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'sucker_punch'
|
2
|
+
|
3
|
+
module ActiveJob
|
4
|
+
module QueueAdapters
|
5
|
+
class SuckerPunchAdapter
|
6
|
+
class << self
|
7
|
+
def queue(job, *args)
|
8
|
+
JobWrapper.new.async.perform(job, *args)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class JobWrapper
|
13
|
+
include SuckerPunch::Job
|
14
|
+
|
15
|
+
def perform(job, *args)
|
16
|
+
job.new.perform *Parameters.deserialize(args)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activejob
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Heinemeier Hansson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activemodel-globalid
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Declare job classes that can be run by a variety of queueing backends.
|
42
|
+
email: david@loudthinking.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- CHANGELOG.md
|
48
|
+
- MIT-LICENSE
|
49
|
+
- lib/active_job.rb
|
50
|
+
- lib/active_job/base.rb
|
51
|
+
- lib/active_job/enqueuing.rb
|
52
|
+
- lib/active_job/gem_version.rb
|
53
|
+
- lib/active_job/log_subscriber.rb
|
54
|
+
- lib/active_job/logging.rb
|
55
|
+
- lib/active_job/parameters.rb
|
56
|
+
- lib/active_job/queue_adapter.rb
|
57
|
+
- lib/active_job/queue_adapters/backburner_adapter.rb
|
58
|
+
- lib/active_job/queue_adapters/delayed_job_adapter.rb
|
59
|
+
- lib/active_job/queue_adapters/inline_adapter.rb
|
60
|
+
- lib/active_job/queue_adapters/que_adapter.rb
|
61
|
+
- lib/active_job/queue_adapters/queue_classic_adapter.rb
|
62
|
+
- lib/active_job/queue_adapters/resque_adapter.rb
|
63
|
+
- lib/active_job/queue_adapters/sidekiq_adapter.rb
|
64
|
+
- lib/active_job/queue_adapters/sneakers_adapter.rb
|
65
|
+
- lib/active_job/queue_adapters/sucker_punch_adapter.rb
|
66
|
+
- lib/active_job/queue_name.rb
|
67
|
+
- lib/active_job/railitie.rb
|
68
|
+
- lib/active_job/version.rb
|
69
|
+
homepage: http://www.rubyonrails.org
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 1.9.3
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.2.2
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Job framework with pluggable queues (will be part of Rails).
|
93
|
+
test_files: []
|
94
|
+
has_rdoc:
|