delayed_job 2.1.4 → 3.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
data/spec/worker_spec.rb CHANGED
@@ -12,26 +12,8 @@ describe Delayed::Worker do
12
12
  end
13
13
 
14
14
  it "should set backend with a symbol" do
15
- Delayed::Worker.backend = :active_record
16
- Delayed::Worker.backend.should == Delayed::Backend::ActiveRecord::Job
17
- end
18
- end
19
-
20
- describe "guess_backend" do
21
- after do
22
- Delayed::Worker.backend = :active_record
23
- end
24
-
25
- it "should set to active_record if nil" do
26
- Delayed::Worker.backend = nil
27
- lambda {
28
- Delayed::Worker.guess_backend
29
- }.should change { Delayed::Worker.backend }.to(Delayed::Backend::ActiveRecord::Job)
30
- end
31
-
32
- it "should not override the existing backend" do
33
- Delayed::Worker.backend = Class.new
34
- lambda { Delayed::Worker.guess_backend }.should_not change { Delayed::Worker.backend }
15
+ Delayed::Worker.backend = :test
16
+ Delayed::Worker.backend.should == Delayed::Backend::Test::Job
35
17
  end
36
18
  end
37
19
  end
@@ -1,31 +1,31 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe YAML do
4
- it "should autoload classes that are unknown at runtime" do
3
+ describe "YAML" do
4
+ it "should autoload classes" do
5
5
  lambda {
6
- obj = YAML.load("--- !ruby/object:Autoloaded::Clazz {}")
7
- obj.class.to_s.should == 'Autoloaded::Clazz'
6
+ yaml = "--- !ruby/class:Autoloaded::Clazz {}\n"
7
+ YAML.load(yaml).should == Autoloaded::Clazz
8
8
  }.should_not raise_error
9
9
  end
10
10
 
11
- it "should autoload structs that are unknown at runtime" do
11
+ it "should autoload the class of a struct" do
12
12
  lambda {
13
- obj = YAML.load("--- !ruby/struct:Autoloaded::Struct {}")
14
- obj.class.to_s.should == 'Autoloaded::Struct'
13
+ yaml = "--- !ruby/class:Autoloaded::Struct {}\n"
14
+ YAML.load(yaml).should == Autoloaded::Struct
15
15
  }.should_not raise_error
16
16
  end
17
17
 
18
- # As we're overriding some of Yaml's internals it is best that our changes
19
- # don't impact other places where Yaml is used. Or at least don't make it
20
- # look like the exception is caused by DJ
21
- it "should not raise exception on poorly formatted yaml" do
22
- lambda do
23
- YAML.load(<<-EOYAML
24
- default:
25
- <<: *login
26
- EOYAML
27
- )
28
- end.should_not raise_error
18
+ it "should autoload the class for the instance of a struct" do
19
+ lambda {
20
+ yaml = "--- !ruby/struct:Autoloaded::InstanceStruct {}"
21
+ YAML.load(yaml).class.should == Autoloaded::InstanceStruct
22
+ }.should_not raise_error
23
+ end
24
+
25
+ it "should autoload the class for the instance" do
26
+ lambda {
27
+ yaml = "--- !ruby/object:Autoloaded::InstanceClazz {}\n"
28
+ YAML.load(yaml).class.should == Autoloaded::InstanceClazz
29
+ }.should_not raise_error
29
30
  end
30
-
31
31
  end
metadata CHANGED
@@ -1,220 +1,194 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: delayed_job
3
- version: !ruby/object:Gem::Version
4
- hash: 3
5
- prerelease:
6
- segments:
7
- - 2
8
- - 1
9
- - 4
10
- version: 2.1.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0.pre
5
+ prerelease: 6
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Chris Gaffney
14
9
  - Brandon Keepers
15
- - "Tobias L\xC3\xBCtke"
10
+ - Tobias Lütke
16
11
  autorequire:
17
12
  bindir: bin
18
13
  cert_chain: []
19
-
20
- date: 2011-02-11 00:00:00 -05:00
21
- default_executable:
22
- dependencies:
23
- - !ruby/object:Gem::Dependency
24
- prerelease: false
25
- type: :runtime
14
+ date: 2011-09-28 00:00:00.000000000Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
26
17
  name: daemons
27
- version_requirements: &id001 !ruby/object:Gem::Requirement
18
+ requirement: &70127307821420 !ruby/object:Gem::Requirement
28
19
  none: false
29
- requirements:
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- hash: 3
33
- segments:
34
- - 0
35
- version: "0"
36
- requirement: *id001
37
- - !ruby/object:Gem::Dependency
38
- prerelease: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
39
24
  type: :runtime
25
+ prerelease: false
26
+ version_requirements: *70127307821420
27
+ - !ruby/object:Gem::Dependency
40
28
  name: activesupport
41
- version_requirements: &id002 !ruby/object:Gem::Requirement
29
+ requirement: &70127307819760 !ruby/object:Gem::Requirement
42
30
  none: false
43
- requirements:
31
+ requirements:
44
32
  - - ~>
45
- - !ruby/object:Gem::Version
46
- hash: 7
47
- segments:
48
- - 3
49
- - 0
50
- version: "3.0"
51
- requirement: *id002
52
- - !ruby/object:Gem::Dependency
33
+ - !ruby/object:Gem::Version
34
+ version: '3.0'
35
+ type: :runtime
53
36
  prerelease: false
37
+ version_requirements: *70127307819760
38
+ - !ruby/object:Gem::Dependency
39
+ name: activerecord
40
+ requirement: &70127307818840 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.0'
54
46
  type: :development
47
+ prerelease: false
48
+ version_requirements: *70127307818840
49
+ - !ruby/object:Gem::Dependency
50
+ name: sqlite3
51
+ requirement: &70127307818160 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *70127307818160
60
+ - !ruby/object:Gem::Dependency
55
61
  name: rails
56
- version_requirements: &id003 !ruby/object:Gem::Requirement
62
+ requirement: &70127307817220 !ruby/object:Gem::Requirement
57
63
  none: false
58
- requirements:
64
+ requirements:
59
65
  - - ~>
60
- - !ruby/object:Gem::Version
61
- hash: 7
62
- segments:
63
- - 3
64
- - 0
65
- version: "3.0"
66
- requirement: *id003
67
- - !ruby/object:Gem::Dependency
68
- prerelease: false
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
69
68
  type: :development
69
+ prerelease: false
70
+ version_requirements: *70127307817220
71
+ - !ruby/object:Gem::Dependency
70
72
  name: rspec
71
- version_requirements: &id004 !ruby/object:Gem::Requirement
73
+ requirement: &70127307816440 !ruby/object:Gem::Requirement
72
74
  none: false
73
- requirements:
75
+ requirements:
74
76
  - - ~>
75
- - !ruby/object:Gem::Version
76
- hash: 3
77
- segments:
78
- - 2
79
- - 0
80
- version: "2.0"
81
- requirement: *id004
82
- - !ruby/object:Gem::Dependency
83
- prerelease: false
77
+ - !ruby/object:Gem::Version
78
+ version: '2.0'
84
79
  type: :development
80
+ prerelease: false
81
+ version_requirements: *70127307816440
82
+ - !ruby/object:Gem::Dependency
85
83
  name: rake
86
- version_requirements: &id005 !ruby/object:Gem::Requirement
84
+ requirement: &70127307815820 !ruby/object:Gem::Requirement
87
85
  none: false
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- hash: 3
92
- segments:
93
- - 0
94
- version: "0"
95
- requirement: *id005
96
- - !ruby/object:Gem::Dependency
97
- prerelease: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
98
90
  type: :development
99
- name: sqlite3
100
- version_requirements: &id006 !ruby/object:Gem::Requirement
101
- none: false
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- hash: 3
106
- segments:
107
- - 0
108
- version: "0"
109
- requirement: *id006
110
- - !ruby/object:Gem::Dependency
111
91
  prerelease: false
112
- type: :development
113
- name: mysql
114
- version_requirements: &id007 !ruby/object:Gem::Requirement
115
- none: false
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- hash: 3
120
- segments:
121
- - 0
122
- version: "0"
123
- requirement: *id007
124
- description: |-
125
- Delayed_job (or DJ) encapsulates the common pattern of asynchronously executing longer tasks in the background. It is a direct extraction from Shopify where the job table is responsible for a multitude of core tasks.
126
-
127
- This gem is collectiveidea's fork (http://github.com/collectiveidea/delayed_job).
128
- email:
92
+ version_requirements: *70127307815820
93
+ description: ! 'Delayed_job (or DJ) encapsulates the common pattern of asynchronously
94
+ executing longer tasks in the background. It is a direct extraction from Shopify
95
+ where the job table is responsible for a multitude of core tasks.
96
+
97
+
98
+ This gem is collectiveidea''s fork (http://github.com/collectiveidea/delayed_job).'
99
+ email:
129
100
  - chris@collectiveidea.com
130
101
  - brandon@opensoul.org
131
102
  executables: []
132
-
133
103
  extensions: []
134
-
135
- extra_rdoc_files:
104
+ extra_rdoc_files:
136
105
  - README.textile
137
- files:
106
+ files:
138
107
  - contrib/delayed_job.monitrc
139
108
  - contrib/delayed_job_multiple.monitrc
140
- - lib/delayed/backend/active_record.rb
141
109
  - lib/delayed/backend/base.rb
142
110
  - lib/delayed/backend/shared_spec.rb
143
111
  - lib/delayed/command.rb
144
112
  - lib/delayed/deserialization_error.rb
113
+ - lib/delayed/lifecycle.rb
145
114
  - lib/delayed/message_sending.rb
146
115
  - lib/delayed/performable_mailer.rb
147
116
  - lib/delayed/performable_method.rb
117
+ - lib/delayed/plugin.rb
118
+ - lib/delayed/plugins/clear_locks.rb
119
+ - lib/delayed/psych_ext.rb
148
120
  - lib/delayed/railtie.rb
149
121
  - lib/delayed/recipes.rb
150
122
  - lib/delayed/serialization/active_record.rb
123
+ - lib/delayed/syck_ext.rb
151
124
  - lib/delayed/tasks.rb
152
125
  - lib/delayed/worker.rb
153
126
  - lib/delayed/yaml_ext.rb
154
127
  - lib/delayed_job.rb
155
128
  - lib/generators/delayed_job/delayed_job_generator.rb
156
- - lib/generators/delayed_job/templates/migration.rb
157
129
  - lib/generators/delayed_job/templates/script
158
130
  - recipes/delayed_job.rb
159
- - spec/active_record_job_spec.rb
160
131
  - spec/autoloaded/clazz.rb
132
+ - spec/autoloaded/instance_clazz.rb
133
+ - spec/autoloaded/instance_struct.rb
161
134
  - spec/autoloaded/struct.rb
162
- - spec/database.yml
135
+ - spec/delayed/backend/test.rb
136
+ - spec/delayed/serialization/test.rb
137
+ - spec/lifecycle_spec.rb
163
138
  - spec/message_sending_spec.rb
164
139
  - spec/performable_mailer_spec.rb
165
140
  - spec/performable_method_spec.rb
166
141
  - spec/sample_jobs.rb
167
142
  - spec/spec_helper.rb
143
+ - spec/test_backend_spec.rb
168
144
  - spec/worker_spec.rb
169
145
  - spec/yaml_ext_spec.rb
170
146
  - MIT-LICENSE
171
147
  - README.textile
172
- has_rdoc: true
173
148
  homepage: http://github.com/collectiveidea/delayed_job
174
149
  licenses: []
175
-
176
150
  post_install_message:
177
- rdoc_options:
151
+ rdoc_options:
178
152
  - --main
179
153
  - README.textile
180
154
  - --inline-source
181
155
  - --line-numbers
182
- require_paths:
156
+ require_paths:
183
157
  - lib
184
- required_ruby_version: !ruby/object:Gem::Requirement
158
+ required_ruby_version: !ruby/object:Gem::Requirement
185
159
  none: false
186
- requirements:
187
- - - ">="
188
- - !ruby/object:Gem::Version
189
- hash: 3
190
- segments:
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ segments:
191
165
  - 0
192
- version: "0"
193
- required_rubygems_version: !ruby/object:Gem::Requirement
166
+ hash: -811957530217889269
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
194
168
  none: false
195
- requirements:
196
- - - ">="
197
- - !ruby/object:Gem::Version
198
- hash: 3
199
- segments:
200
- - 0
201
- version: "0"
169
+ requirements:
170
+ - - ! '>'
171
+ - !ruby/object:Gem::Version
172
+ version: 1.3.1
202
173
  requirements: []
203
-
204
174
  rubyforge_project:
205
- rubygems_version: 1.5.0
175
+ rubygems_version: 1.8.6
206
176
  signing_key:
207
177
  specification_version: 3
208
178
  summary: Database-backed asynchronous priority queue system -- Extracted from Shopify
209
- test_files:
210
- - spec/active_record_job_spec.rb
179
+ test_files:
211
180
  - spec/autoloaded/clazz.rb
181
+ - spec/autoloaded/instance_clazz.rb
182
+ - spec/autoloaded/instance_struct.rb
212
183
  - spec/autoloaded/struct.rb
213
- - spec/database.yml
184
+ - spec/delayed/backend/test.rb
185
+ - spec/delayed/serialization/test.rb
186
+ - spec/lifecycle_spec.rb
214
187
  - spec/message_sending_spec.rb
215
188
  - spec/performable_mailer_spec.rb
216
189
  - spec/performable_method_spec.rb
217
190
  - spec/sample_jobs.rb
218
191
  - spec/spec_helper.rb
192
+ - spec/test_backend_spec.rb
219
193
  - spec/worker_spec.rb
220
194
  - spec/yaml_ext_spec.rb
@@ -1,82 +0,0 @@
1
- require 'active_record'
2
-
3
- module Delayed
4
- module Backend
5
- module ActiveRecord
6
- # A job object that is persisted to the database.
7
- # Contains the work object as a YAML field.
8
- class Job < ::ActiveRecord::Base
9
- include Delayed::Backend::Base
10
- set_table_name :delayed_jobs
11
-
12
- before_save :set_default_run_at
13
-
14
- scope :ready_to_run, lambda {|worker_name, max_run_time|
15
- where(['(run_at <= ? AND (locked_at IS NULL OR locked_at < ?) OR locked_by = ?) AND failed_at IS NULL', db_time_now, db_time_now - max_run_time, worker_name])
16
- }
17
- scope :by_priority, order('priority ASC, run_at ASC')
18
-
19
- def self.before_fork
20
- ::ActiveRecord::Base.clear_all_connections!
21
- end
22
-
23
- def self.after_fork
24
- ::ActiveRecord::Base.establish_connection
25
- end
26
-
27
- # When a worker is exiting, make sure we don't have any locked jobs.
28
- def self.clear_locks!(worker_name)
29
- update_all("locked_by = null, locked_at = null", ["locked_by = ?", worker_name])
30
- end
31
-
32
- # Find a few candidate jobs to run (in case some immediately get locked by others).
33
- def self.find_available(worker_name, limit = 5, max_run_time = Worker.max_run_time)
34
- scope = self.ready_to_run(worker_name, max_run_time)
35
- scope = scope.scoped(:conditions => ['priority >= ?', Worker.min_priority]) if Worker.min_priority
36
- scope = scope.scoped(:conditions => ['priority <= ?', Worker.max_priority]) if Worker.max_priority
37
-
38
- ::ActiveRecord::Base.silence do
39
- scope.by_priority.all(:limit => limit)
40
- end
41
- end
42
-
43
- # Lock this job for this worker.
44
- # Returns true if we have the lock, false otherwise.
45
- def lock_exclusively!(max_run_time, worker)
46
- now = self.class.db_time_now
47
- affected_rows = if locked_by != worker
48
- # We don't own this job so we will update the locked_by name and the locked_at
49
- self.class.update_all(["locked_at = ?, locked_by = ?", now, worker], ["id = ? and (locked_at is null or locked_at < ?) and (run_at <= ?)", id, (now - max_run_time.to_i), now])
50
- else
51
- # We already own this job, this may happen if the job queue crashes.
52
- # Simply resume and update the locked_at
53
- self.class.update_all(["locked_at = ?", now], ["id = ? and locked_by = ?", id, worker])
54
- end
55
- if affected_rows == 1
56
- self.locked_at = now
57
- self.locked_by = worker
58
- self.locked_at_will_change!
59
- self.locked_by_will_change!
60
- return true
61
- else
62
- return false
63
- end
64
- end
65
-
66
- # Get the current time (GMT or local depending on DB)
67
- # Note: This does not ping the DB to get the time, so all your clients
68
- # must have syncronized clocks.
69
- def self.db_time_now
70
- if Time.zone
71
- Time.zone.now
72
- elsif ::ActiveRecord::Base.default_timezone == :utc
73
- Time.now.utc
74
- else
75
- Time.now
76
- end
77
- end
78
-
79
- end
80
- end
81
- end
82
- end
@@ -1,21 +0,0 @@
1
- class CreateDelayedJobs < ActiveRecord::Migration
2
- def self.up
3
- create_table :delayed_jobs, :force => true do |table|
4
- table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue
5
- table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually.
6
- table.text :handler # YAML-encoded string of the object that will do work
7
- table.text :last_error # reason for last failure (See Note below)
8
- table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
9
- table.datetime :locked_at # Set when a client is working on this object
10
- table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
11
- table.string :locked_by # Who is working on this object (if locked)
12
- table.timestamps
13
- end
14
-
15
- add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority'
16
- end
17
-
18
- def self.down
19
- drop_table :delayed_jobs
20
- end
21
- end
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
- require 'delayed/backend/active_record'
3
-
4
- describe Delayed::Backend::ActiveRecord::Job do
5
- after do
6
- Time.zone = nil
7
- end
8
-
9
- it_should_behave_like 'a delayed_job backend'
10
-
11
- context "db_time_now" do
12
- it "should return time in current time zone if set" do
13
- Time.zone = 'Eastern Time (US & Canada)'
14
- %w(EST EDT).should include(Delayed::Job.db_time_now.zone)
15
- end
16
-
17
- it "should return UTC time if that is the AR default" do
18
- Time.zone = nil
19
- ActiveRecord::Base.default_timezone = :utc
20
- Delayed::Backend::ActiveRecord::Job.db_time_now.zone.should == 'UTC'
21
- end
22
-
23
- it "should return local time if that is the AR default" do
24
- Time.zone = 'Central Time (US & Canada)'
25
- ActiveRecord::Base.default_timezone = :local
26
- %w(CST CDT).should include(Delayed::Backend::ActiveRecord::Job.db_time_now.zone)
27
- end
28
- end
29
-
30
- describe "after_fork" do
31
- it "should call reconnect on the connection" do
32
- ActiveRecord::Base.should_receive(:establish_connection)
33
- Delayed::Backend::ActiveRecord::Job.after_fork
34
- end
35
- end
36
- end
data/spec/database.yml DELETED
@@ -1,4 +0,0 @@
1
- mysql:
2
- adapter: mysql
3
- database: delayed_job
4
- username: root