delayed_job_ironmq 1.0.2 → 2.0.0.pre1

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: 82cb55dc34f6dc0e2110bdca7e4bcd3fdd8affca
4
- data.tar.gz: 12cc3347deb24b7fbd95cfe1ff135d995ac60f63
3
+ metadata.gz: c6aa6fcf508e50c31a9d914116918d3cbc9c393d
4
+ data.tar.gz: 3ea4085dc5fcaf29c1386a6a2c198a4e9c19d899
5
5
  SHA512:
6
- metadata.gz: 6d12fce9d30d8bf403d3bdcb9445e69fac5fa7c77b1e7475bdcb29e48615619acbafd7c7573a13dd569d5e160725223bbba048ecc0abcb8fb05f6cf8d8d2da83
7
- data.tar.gz: 4c563d142bed4edc8be79078fd544269a81ff6bb3eade695180bc3ce143d534bf946fea95643af47b6f0d9209f7294625e58b20a37ec85e69ae9242754dd3c41
6
+ metadata.gz: 7d3c01a86a3b1700d4d50be0bfdec61967a2c83bb0863091fa26409c32586e84e431e8a17172220c0d2afb895e405b5e80b85a5599d75237d234c7ff9e73f09e
7
+ data.tar.gz: e06b1b5e06c2addc0ae81c3c7c48c702fdfa6f16ad9e9acf8c22639a71974d7ee92dd1ecbbacd60457da3d0a116dad05589b916964eb62bf9b49d57c137d896f
data/Gemfile.lock CHANGED
@@ -1,40 +1,50 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- delayed_job_ironmq (1.0.2)
5
- delayed_job (>= 3.0.0)
6
- iron_mq (>= 4.0.0)
4
+ delayed_job_ironmq (2.0.0.pre1)
5
+ delayed_job (~> 4.0.6)
6
+ iron_mq (= 6.0.0.pre1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (3.2.18)
12
- i18n (~> 0.6, >= 0.6.4)
13
- multi_json (~> 1.0)
14
- delayed_job (3.0.5)
15
- activesupport (~> 3.0)
11
+ activesupport (4.2.0)
12
+ i18n (~> 0.7)
13
+ json (~> 1.7, >= 1.7.7)
14
+ minitest (~> 5.1)
15
+ thread_safe (~> 0.3, >= 0.3.4)
16
+ tzinfo (~> 1.1)
17
+ delayed_job (4.0.6)
18
+ activesupport (>= 3.0, < 5.0)
16
19
  diff-lcs (1.2.5)
17
- i18n (0.6.9)
18
- iron_core (1.0.3)
19
- rest (>= 2.6.4)
20
- iron_mq (5.0.1)
20
+ i18n (0.7.0)
21
+ iron_core (1.0.7)
22
+ rest (>= 3.0.4)
23
+ iron_mq (6.0.0.pre1)
21
24
  iron_core (>= 0.5.1)
22
- multi_json (1.10.0)
25
+ json (1.8.2)
26
+ minitest (5.5.1)
23
27
  net-http-persistent (2.9.4)
24
- netrc (0.7.7)
25
- rest (2.7.1)
28
+ netrc (0.10.3)
29
+ rest (3.0.6)
26
30
  net-http-persistent (>= 2.9.1)
27
- rest_client (>= 1.7.1)
28
- rest_client (1.7.3)
29
- netrc (~> 0.7.7)
30
- rspec (2.14.1)
31
- rspec-core (~> 2.14.0)
32
- rspec-expectations (~> 2.14.0)
33
- rspec-mocks (~> 2.14.0)
34
- rspec-core (2.14.8)
35
- rspec-expectations (2.14.5)
36
- diff-lcs (>= 1.1.3, < 2.0)
37
- rspec-mocks (2.14.6)
31
+ netrc
32
+ rspec (3.2.0)
33
+ rspec-core (~> 3.2.0)
34
+ rspec-expectations (~> 3.2.0)
35
+ rspec-mocks (~> 3.2.0)
36
+ rspec-core (3.2.1)
37
+ rspec-support (~> 3.2.0)
38
+ rspec-expectations (3.2.0)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.2.0)
41
+ rspec-mocks (3.2.1)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.2.0)
44
+ rspec-support (3.2.2)
45
+ thread_safe (0.3.4)
46
+ tzinfo (1.2.2)
47
+ thread_safe (~> 0.1)
38
48
 
39
49
  PLATFORMS
40
50
  ruby
data/README.md CHANGED
@@ -11,15 +11,26 @@ To start using delayed_job_ironmq, you need to sign up for Iron.io and setup you
11
11
 
12
12
  1. Go to http://iron.io/ and sign up.
13
13
  2. Get an Oauth Token at http://hud.iron.io/tokens
14
- 3. Add an iron.json file or setup environment variables for authentication. See http://dev.iron.io/articles/configuration/ for details.
14
+ 3. Add an iron.json file or setup environment variables for authentication. See http://dev.iron.io/mq/reference/configuration/ for details.
15
+
16
+ If you want to set the Host, Post, and Protocol specifically, simply include those keys in that project's iron.json file:
17
+ ```json
18
+ {
19
+ "project_id": "PROJECT ID HERE",
20
+ "token": "YOUR TOKEN HERE"
21
+ "port": 443,
22
+ "protocol": "https",
23
+ "host":"mq-v3-aws-us-east-1.iron.io"
24
+ }
25
+ ```
15
26
 
16
27
  ## Installation
17
28
 
18
29
  Add the gems to your `Gemfile:`
19
30
 
20
31
  ```ruby
21
- gem 'delayed_job'
22
- gem 'delayed_job_ironmq'
32
+ gem 'delayed_job', '~> 4.0.6'
33
+ gem 'delayed_job_ironmq', '2.0.0.pre1'
23
34
  ```
24
35
 
25
36
  Optionally: Add an initializer (`config/initializers/delayed_job.rb`):
@@ -32,8 +43,10 @@ Delayed::Worker.configure do |config|
32
43
  config.delay = 0 # Time to wait before message will be available on the queue
33
44
  config.timeout = 5.minutes # The time in seconds to wait after message is taken off the queue, before it is put back on. Delete before :timeout to ensure it does not go back on the queue.
34
45
  config.expires_in = 7.days # After this time, message will be automatically removed from the queue.
46
+ config.error_queue = 'error_queue' # The failed jobs will be placed into the error queue
35
47
  end
36
48
  ```
49
+ If you want to keep failed jobs, set `Delayed::Worker.destroy_failed_jobs = false`. The failed jobs will be placed into the error queue if failures exceed `Worker.max_attempts`.
37
50
 
38
51
  ## Usage
39
52
 
@@ -56,6 +69,27 @@ user = User.new
56
69
  user.delay.background_stuff
57
70
  ```
58
71
 
72
+ Or declare a job using activejob like so:
73
+
74
+ ```ruby
75
+ class MyJob < ActiveJob::Base
76
+ queue_as :default
77
+ def perform(*args)
78
+ puts "I run in the background"
79
+ end
80
+ end
81
+ ```
82
+
83
+ Then enqueue a job:
84
+
85
+ ```ruby
86
+ MyJob.perform_later record # Enqueue a job to be performed as soon the queueing system is free.
87
+ ```
88
+
89
+ ```ruby
90
+ MyJob.set(wait: 1.week).perform_later(record) # Enqueue a job to be performed 1 week from now.
91
+ ```
92
+
59
93
  ## Start worker process
60
94
 
61
95
  rake jobs:work
@@ -64,7 +98,7 @@ That will start pulling jobs off the queue and processing them.
64
98
 
65
99
  # Demo Rails Application
66
100
 
67
- Here's a demo rails app you can clone and try it out: https://github.com/treeder/delayed_job_with_iron_mq
101
+ Here's a demo rails app you can clone and try it out: https://github.com/treeder/delayed_job_ironmq_example
68
102
 
69
103
  # Using with Heroku
70
104
 
@@ -17,8 +17,8 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.required_rubygems_version = ">= 1.3.6"
19
19
  gem.required_ruby_version = Gem::Requirement.new(">= 1.8")
20
- gem.add_runtime_dependency "iron_mq", ">= 4.0.0"
21
- gem.add_runtime_dependency "delayed_job", ">= 3.0.0"
20
+ gem.add_runtime_dependency "iron_mq", "6.0.0.pre1"
21
+ gem.add_runtime_dependency "delayed_job", "~> 4.0.6"
22
22
 
23
23
  gem.add_development_dependency "rspec"
24
24
  end
@@ -31,22 +31,30 @@ module Delayed
31
31
 
32
32
  def find_available(worker_name, limit = 5, max_run_time = Worker.max_run_time)
33
33
  Delayed::Worker.available_priorities.each do |priority|
34
- message = ironmq.queue(queue_name(priority)).get
34
+ message = nil
35
+ begin
36
+ message = ironmq.queue(queue_name(priority)).get
37
+ rescue Exception => e
38
+ Delayed::Worker.logger.warn(e.message)
39
+ end
35
40
  return [Delayed::Backend::Ironmq::Job.new(message)] if message
36
41
  end
37
42
  []
38
43
  end
39
44
 
40
45
  def delete_all
41
- deleted = 0
42
46
  Delayed::Worker.available_priorities.each do |priority|
43
47
  loop do
44
- msgs = ironmq.queue(queue_name(priority)).get(:n => 1000)
45
- break if msgs.blank?
46
- msgs.each do |msg|
47
- msg.delete
48
- deleted += 1
48
+ msgs = nil
49
+ queue = queue_name(priority)
50
+ begin
51
+ msgs = ironmq.queue(queue).get(:n => 1000)
52
+ rescue Exception => e
53
+ Delayed::Worker.logger.warn(e.message)
49
54
  end
55
+
56
+ break if msgs.blank?
57
+ ironmq.queue(queue).delete_reserved_messages(msgs)
50
58
  end
51
59
  end
52
60
  end
@@ -1,5 +1,6 @@
1
1
  class IronMqConfig
2
2
  attr_accessor :token, :project_id,
3
3
  :queue_name, :delay, :timeout,
4
- :expires_in, :available_priorities
4
+ :expires_in, :available_priorities,
5
+ :error_queue, :logger
5
6
  end
@@ -27,16 +27,17 @@ module Delayed
27
27
  data.symbolize_keys!
28
28
  payload_obj = data.delete(:payload_object) || data.delete(:handler)
29
29
 
30
- @queue_name = data[:queue_name] || Delayed::Worker.queue_name
31
- @delay = data[:delay] || Delayed::Worker.delay
32
- @timeout = data[:timeout] || Delayed::Worker.timeout
33
- @expires_in = data[:expires_in] || Delayed::Worker.expires_in
34
- @attributes = data
30
+ @queue_name = data[:queue_name] || Delayed::Worker.queue_name
31
+ @delay = data[:delay] || Delayed::Worker.delay
32
+ @timeout = data[:timeout] || Delayed::Worker.timeout
33
+ @expires_in = data[:expires_in] || Delayed::Worker.expires_in
34
+ @error_queue = data[:error_queue] || Delayed::Worker.error_queue
35
+ @attributes = data
35
36
  self.payload_object = payload_obj
36
37
  end
37
38
 
38
39
  def payload_object
39
- @payload_object ||= YAML.load(self.handler)
40
+ @payload_object ||= yaml_load
40
41
  rescue TypeError, LoadError, NameError, ArgumentError => e
41
42
  raise DeserializationError,
42
43
  "Job failed to load: #{e.message}. Handler: #{handler.inspect}"
@@ -44,7 +45,7 @@ module Delayed
44
45
 
45
46
  def payload_object=(object)
46
47
  if object.is_a? String
47
- @payload_object = YAML.load(object)
48
+ @payload_object = yaml_load(object)
48
49
  self.handler = object
49
50
  else
50
51
  @payload_object = object
@@ -58,6 +59,10 @@ module Delayed
58
59
  end
59
60
  payload = JSON.dump(@attributes)
60
61
 
62
+ if run_at && run_at.utc >= self.class.db_time_now
63
+ @delay = (run_at.utc - self.class.db_time_now).round
64
+ end
65
+
61
66
  @msg.delete if @msg
62
67
 
63
68
  ironmq.queue(queue_name).post(payload,
@@ -78,8 +83,11 @@ module Delayed
78
83
  end
79
84
 
80
85
  def fail!
86
+ ironmq.queue(@error_queue).post(@msg.body,
87
+ :timeout => @timeout,
88
+ :delay => @delay,
89
+ :expires_in => @expires_in)
81
90
  destroy
82
- # v2: move to separate queue
83
91
  end
84
92
 
85
93
  def update_attributes(attributes)
@@ -116,6 +124,11 @@ module Delayed
116
124
  def ironmq
117
125
  ::Delayed::Worker.ironmq
118
126
  end
127
+
128
+ def yaml_load(object)
129
+ object ||= self.handler
130
+ YAML.respond_to?(:load_dj) ? YAML.load_dj(object) : YAML.load(object)
131
+ end
119
132
  end
120
133
  end
121
134
  end
@@ -1,7 +1,7 @@
1
1
  module Delayed
2
2
  module Backend
3
3
  module Ironmq
4
- VERSION = "1.0.2"
4
+ VERSION = "2.0.0.pre1"
5
5
  end
6
6
  end
7
7
  end
@@ -3,8 +3,8 @@ require_relative 'iron_mq_config'
3
3
  module Delayed
4
4
  class Worker
5
5
  class << self
6
- attr_accessor :config, :ironmq,
7
- :queue_name, :delay, :timeout, :expires_in, :available_priorities
6
+ attr_accessor :config, :ironmq, :queue_name, :delay, :timeout, :expires_in,
7
+ :available_priorities, :error_queue, :logger
8
8
 
9
9
  def configure
10
10
  yield(config)
@@ -12,6 +12,7 @@ module Delayed
12
12
  self.delay = config.delay || 0
13
13
  self.timeout = config.timeout || 5.minutes
14
14
  self.expires_in = config.expires_in || 7.days
15
+ self.error_queue = config.error_queue || 'error_queue'
15
16
 
16
17
  priorities = config.available_priorities || [0]
17
18
  if priorities.include?(0) && priorities.all? { |p| p.is_a?(Integer) }
@@ -19,6 +20,9 @@ module Delayed
19
20
  else
20
21
  raise ArgumentError, "available_priorities option has wrong format. Please provide array of Integer values, includes zero. Default is [0]."
21
22
  end
23
+
24
+ self.logger = config.logger || Logger.new(STDOUT)
25
+ self.logger.level = Logger::WARN
22
26
  end
23
27
 
24
28
  def config
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_job_ironmq
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Shapiotko
@@ -9,48 +9,48 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-18 00:00:00.000000000 Z
12
+ date: 2015-03-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: iron_mq
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 4.0.0
20
+ version: 6.0.0.pre1
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - '='
26
26
  - !ruby/object:Gem::Version
27
- version: 4.0.0
27
+ version: 6.0.0.pre1
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: delayed_job
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: 3.0.0
34
+ version: 4.0.6
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: 3.0.0
41
+ version: 4.0.6
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rspec
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '>='
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - '>='
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  description: IronMQ backend for delayed_job
@@ -61,7 +61,7 @@ executables: []
61
61
  extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
- - .gitignore
64
+ - ".gitignore"
65
65
  - Gemfile
66
66
  - Gemfile.lock
67
67
  - LICENSE
@@ -86,17 +86,17 @@ require_paths:
86
86
  - lib
87
87
  required_ruby_version: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - '>='
89
+ - - ">="
90
90
  - !ruby/object:Gem::Version
91
91
  version: '1.8'
92
92
  required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 1.3.6
97
97
  requirements: []
98
98
  rubyforge_project:
99
- rubygems_version: 2.2.2
99
+ rubygems_version: 2.4.6
100
100
  signing_key:
101
101
  specification_version: 4
102
102
  summary: IronMQ backend for delayed_job