activejob_disque_adapter 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf837908a2b09ae4eeaa6070e358602a58573f56
4
- data.tar.gz: 9faa17b8dd76fcd5f4dc3b41e64e05f79d3cc591
3
+ metadata.gz: 2352c90c6cef05344971d8a1e0eb428f4a2d51e2
4
+ data.tar.gz: b3f180d5e6ee0306d1877bd0f976df34950d6d00
5
5
  SHA512:
6
- metadata.gz: a22a16531b5cb3fb978e90823ac9e66939f210eaa2d18c0a9d9c144e2c9904ecbad65ddd728d5159d08cbbc931a65d89d6e9ccdf3cc5cba90f6aad9b781fbc19
7
- data.tar.gz: 616f08c902ff86c3109808a8653db030d660c02b779ebebffda513c5df9473fba462e2974ea749e48ebe3af1c06ef08ff3b26145718f4e80887b844290f4dd25
6
+ metadata.gz: efdc2b46c01b8869665704fe1e5fa367a88837227fd7bdaf74bc119825226f5915f91bc86bf7c71b82961a8735046527a5d8123e6833afbe6ba5a5f8baa5e2f2
7
+ data.tar.gz: 819e1e9b9e3e77397fa5aa4f58b2e6f0a99eb102fb5848a65fe8d17bae76f3b354b780f20b88e4083838654d99ae26659fec1b8993872f3b331130910f6b946f
@@ -0,0 +1,66 @@
1
+ ## Rails <3 Disque
2
+
3
+ This gem provides a simple way to use [antirez](http://antirez.com/)'s [Disque](https://github.com/antirez/disque) as a backend for your Rails [ActiveJob](http://edgeguides.rubyonrails.org/active_job_basics.html) workers.
4
+
5
+
6
+ ### Installation and Setup
7
+
8
+ Add this gem to your Gemfile.
9
+
10
+ ```ruby
11
+ gem 'rails', '4.2.3'
12
+ gem 'activejob_disque_adapter'
13
+ ```
14
+
15
+ And set your Rails application to use it in `config/application.rb` (or `config/environments/*`, depending on your preference)
16
+
17
+ ```ruby
18
+ module YourApp
19
+ class Application < Rails::Application
20
+ config.active_job.queue_adapter = :disque
21
+ end
22
+ end
23
+ ```
24
+
25
+ That's all you need! You can then go on to write standard ActiveJob classes, which will be enqueued to Disque when you call `#perform_later` on them.
26
+
27
+
28
+ ## Running your jobs
29
+
30
+ This gem also includes a handy class called `Disque::ActiveJobWorker` and a rake task that leverages it. In order to run your jobs you can simply call `rake disque:work` from your Procfile, like so:
31
+
32
+ ```Procfile
33
+ disque_high: DISQUE_QUEUES=urgent rake disque:work
34
+ disque_all: DISQUE_QUEUES=urgent,medium,low rake disque:work
35
+ ```
36
+
37
+ ## Configuration
38
+
39
+ You can configure the Disque adapter and Worker programatically or via environment variables, this is the list of configurable parameters:
40
+
41
+ | Parameter | ENV Variable | Default Value | Description
42
+ |:---------:|:---------------:|:-----------------|:-----------:|
43
+ | Nodes | DISQUE_NODES | 'localhost:7711' | This is the list of Disque servers to connect to, it can be a single node, a list of comma-separated nodes or an array of nodes (when done programatically) |
44
+ | Auth | DISQUE_AUTH | '' | Authorization credentials for Disque. |
45
+ | Timeout | DISQUE_TIMEOUT | '100' | Time in milliseconds that the client will wait for the Disque server to acknowledge and replicate a job |
46
+ | Cycle | DISQUE_CYCLE | '1000' | The client keeps track of which nodes are providing more jobs, after the amount of operations specified in cycle it tries to connect to the preferred node. |
47
+ | Queues | DISQUE_QUEUES | 'default' | The list of queues that `Disque::ActiveJobWorker` will listen to, it can be a single queue name, a list of comma-separated queues or an array of queue names (when done programatically) |
48
+
49
+
50
+
51
+ #### Environment Variables
52
+
53
+ ```.env
54
+ DISQUE_QUEUES="urgent,medium,low"
55
+ DISQUE_NODES="localhost:7711,localhost:8822"
56
+ DISQUE_TIMEOUT=200
57
+ ```
58
+
59
+ #### Programatically
60
+
61
+ ```Ruby
62
+ # Keep in mind #run is a blocking action, it will loop through the queues finding jobs to execute.
63
+ Disque::ActiveJobWorker.new(
64
+ queues: %w(urgent medium)
65
+ ).run
66
+ ```
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "activejob_disque_adapter"
3
- s.version = "0.0.2"
3
+ s.version = "0.0.3"
4
4
  s.summary = "ActiveJob adapter for Disque backends"
5
5
  s.description = "Fills the gap between ActiveJob and Disque"
6
6
  s.authors = ["pote"]
@@ -11,5 +11,6 @@ Gem::Specification.new do |s|
11
11
  s.files = `git ls-files`.split("\n")
12
12
 
13
13
  s.add_dependency "disque"
14
+ s.add_dependency "activesupport"
14
15
  s.add_development_dependency "cutest"
15
16
  end
@@ -1,4 +1,5 @@
1
1
  require 'disque'
2
+ require 'active_support/json'
2
3
 
3
4
  module ActiveJob
4
5
  module QueueAdapters
@@ -6,7 +7,7 @@ module ActiveJob
6
7
  def self.enqueue(job)
7
8
  client.push(
8
9
  job.queue_name,
9
- job.serialize,
10
+ ActiveSupport::JSON.encode(job.serialize),
10
11
  @disque_timeout
11
12
  )
12
13
  end
@@ -14,7 +15,7 @@ module ActiveJob
14
15
  def self.enqueue_at(job, timestamp)
15
16
  client.push(
16
17
  job.queue_name,
17
- job.serialize,
18
+ ActiveSupport::JSON.encode(job.serialize),
18
19
  @disque_timeout,
19
20
  delay: timestamp.to_i - Time.now.to_i
20
21
  )
@@ -26,7 +27,7 @@ module ActiveJob
26
27
  @disque_client ||= client || Disque.new(
27
28
  ENV.fetch('DISQUE_NODES', 'localhost:7711'),
28
29
  auth: ENV.fetch('DISQUE_AUTH', nil),
29
- cycle: ENV.fetch('DISQUE_CYCLE', '20000').to_i
30
+ cycle: ENV.fetch('DISQUE_CYCLE', '1000').to_i
30
31
  )
31
32
  end
32
33
  end
@@ -0,0 +1,8 @@
1
+ require 'active_job/queue_adapters/disque_adapter'
2
+ require 'disque/active_job_worker'
3
+
4
+ class Disque::WorkTask < Rails::Railtie
5
+ rake_tasks do
6
+ load 'disque/tasks/work.rake'
7
+ end
8
+ end
@@ -1,9 +1,8 @@
1
- require 'activesupport'
2
1
  require 'disque'
3
- require 'json'
2
+ require 'active_support/json'
4
3
 
5
- module ActiveJob
6
- class DisqueWorker
4
+ class Disque
5
+ class ActiveJobWorker
7
6
  attr_reader :disque_client,
8
7
  :disque_queues,
9
8
  :disque_timeout,
@@ -20,7 +19,18 @@ module ActiveJob
20
19
  cycle: ENV.fetch('DISQUE_CYCLE', '20000').to_i
21
20
  )
22
21
 
23
- @disque_queues = (queues || ENV.fetch('DISQUE_QUEUES','default')).split(',')
22
+ @disque_queues = case
23
+ when queues.is_a?(Array)
24
+ queues
25
+ when queues.is_a?(String)
26
+ queues.split(',')
27
+ when queues.nil?
28
+ ENV.fetch('DISQUE_QUEUES', 'default').split(',')
29
+ else
30
+ raise 'Invalid Disque Queues'
31
+ end
32
+
33
+
24
34
  @disque_count = count
25
35
  @disque_timeout = timeout
26
36
 
@@ -34,11 +44,9 @@ module ActiveJob
34
44
  timeout: disque_timeout,
35
45
  count: disque_count
36
46
  ) do |serialized_job, _|
37
- job = JSON.parse(serialized_job)
38
- puts "Processing Job: #{ job }"
39
- klass = job.fetch('job_class').classify.constantize
40
- klass.new(job.fetch('arguments')).perform_now
41
- puts "Done"
47
+ ActiveJob::Base.deserialize(
48
+ ActiveSupport::JSON.decode(serialized_job)
49
+ ).perform_now
42
50
  end
43
51
  end
44
52
  end
@@ -0,0 +1,9 @@
1
+ require 'disque/active_job_worker'
2
+
3
+ namespace :disque do
4
+ desc 'Listens to and executes ActiveJob Disque jobs'
5
+ task work: :environment do
6
+ Disque::ActiveJobWorker.run
7
+ end
8
+ end
9
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activejob_disque_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - pote
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-09 00:00:00.000000000 Z
11
+ date: 2015-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: disque
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
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'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: cutest
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -46,11 +60,12 @@ extensions: []
46
60
  extra_rdoc_files: []
47
61
  files:
48
62
  - ".gitignore"
63
+ - README.md
49
64
  - activejob_disque_adapter.gemspec
50
- - lib/active_job.rb
51
- - lib/active_job/disque_worker.rb
52
- - lib/active_job/queue_adapters.rb
53
65
  - lib/active_job/queue_adapters/disque_adapter.rb
66
+ - lib/activejob_disque_adapter.rb
67
+ - lib/disque/active_job_worker.rb
68
+ - lib/disque/tasks/work.rake
54
69
  homepage: https://github.com/pote/activejob_disque_adapter
55
70
  licenses:
56
71
  - MIT
@@ -1,6 +0,0 @@
1
- require 'activesupport'
2
-
3
- module ActiveJob
4
- extend ActiveSupport::Autoload
5
- autoload :DisqueWorker
6
- end
@@ -1,4 +0,0 @@
1
- module ActiveJob::QueueAdapters
2
- extend ActiveSupport::Autoload
3
- autoload :DisqueAdapter
4
- end