drewda_delayed_job 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.textile +314 -0
  3. data/contrib/delayed_job.monitrc +14 -0
  4. data/contrib/delayed_job_multiple.monitrc +23 -0
  5. data/lib/delayed/backend/base.rb +184 -0
  6. data/lib/delayed/backend/shared_spec.rb +595 -0
  7. data/lib/delayed/command.rb +108 -0
  8. data/lib/delayed/deserialization_error.rb +4 -0
  9. data/lib/delayed/lifecycle.rb +84 -0
  10. data/lib/delayed/message_sending.rb +54 -0
  11. data/lib/delayed/performable_mailer.rb +21 -0
  12. data/lib/delayed/performable_method.rb +37 -0
  13. data/lib/delayed/plugin.rb +15 -0
  14. data/lib/delayed/plugins/clear_locks.rb +15 -0
  15. data/lib/delayed/psych_ext.rb +132 -0
  16. data/lib/delayed/railtie.rb +16 -0
  17. data/lib/delayed/recipes.rb +50 -0
  18. data/lib/delayed/serialization/active_record.rb +19 -0
  19. data/lib/delayed/syck_ext.rb +34 -0
  20. data/lib/delayed/tasks.rb +11 -0
  21. data/lib/delayed/worker.rb +242 -0
  22. data/lib/delayed/yaml_ext.rb +10 -0
  23. data/lib/delayed_job.rb +21 -0
  24. data/lib/generators/delayed_job/delayed_job_generator.rb +11 -0
  25. data/lib/generators/delayed_job/templates/script +5 -0
  26. data/recipes/delayed_job.rb +1 -0
  27. data/spec/autoloaded/clazz.rb +7 -0
  28. data/spec/autoloaded/instance_clazz.rb +6 -0
  29. data/spec/autoloaded/instance_struct.rb +6 -0
  30. data/spec/autoloaded/struct.rb +7 -0
  31. data/spec/delayed/backend/test.rb +113 -0
  32. data/spec/delayed/serialization/test.rb +0 -0
  33. data/spec/fixtures/bad_alias.yml +1 -0
  34. data/spec/lifecycle_spec.rb +67 -0
  35. data/spec/message_sending_spec.rb +113 -0
  36. data/spec/performable_mailer_spec.rb +44 -0
  37. data/spec/performable_method_spec.rb +89 -0
  38. data/spec/sample_jobs.rb +75 -0
  39. data/spec/spec_helper.rb +53 -0
  40. data/spec/test_backend_spec.rb +13 -0
  41. data/spec/worker_spec.rb +19 -0
  42. data/spec/yaml_ext_spec.rb +41 -0
  43. metadata +214 -0
@@ -0,0 +1,75 @@
1
+ class NamedJob < Struct.new(:perform)
2
+ def display_name
3
+ 'named_job'
4
+ end
5
+ end
6
+
7
+ class SimpleJob
8
+ cattr_accessor :runs; self.runs = 0
9
+ def perform; @@runs += 1; end
10
+ end
11
+
12
+ class ErrorJob
13
+ cattr_accessor :runs; self.runs = 0
14
+ def perform; raise 'did not work'; end
15
+ end
16
+
17
+ class CustomRescheduleJob < Struct.new(:offset)
18
+ cattr_accessor :runs; self.runs = 0
19
+ def perform; raise 'did not work'; end
20
+ def reschedule_at(time, attempts); time + offset; end
21
+ end
22
+
23
+ class LongRunningJob
24
+ def perform; sleep 250; end
25
+ end
26
+
27
+ class OnPermanentFailureJob < SimpleJob
28
+ def failure; end
29
+ def max_attempts; 1; end
30
+ end
31
+
32
+ module M
33
+ class ModuleJob
34
+ cattr_accessor :runs; self.runs = 0
35
+ def perform; @@runs += 1; end
36
+ end
37
+ end
38
+
39
+ class CallbackJob
40
+ cattr_accessor :messages
41
+
42
+ def enqueue(job)
43
+ self.class.messages << 'enqueue'
44
+ end
45
+
46
+ def before(job)
47
+ self.class.messages << 'before'
48
+ end
49
+
50
+ def perform
51
+ self.class.messages << 'perform'
52
+ end
53
+
54
+ def after(job)
55
+ self.class.messages << 'after'
56
+ end
57
+
58
+ def success(job)
59
+ self.class.messages << 'success'
60
+ end
61
+
62
+ def error(job, error)
63
+ self.class.messages << "error: #{error.class}"
64
+ end
65
+
66
+ def failure(job)
67
+ self.class.messages << 'failure'
68
+ end
69
+ end
70
+
71
+ class EnqueueJobMod < SimpleJob
72
+ def enqueue(job)
73
+ job.run_at = 20.minutes.from_now
74
+ end
75
+ end
@@ -0,0 +1,53 @@
1
+ unless ENV['CI']
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+ end
5
+
6
+ require 'bundler/setup'
7
+ require 'logger'
8
+
9
+ require 'action_mailer'
10
+ require 'active_support/dependencies'
11
+ require 'active_record'
12
+
13
+ require 'delayed_job'
14
+ require 'delayed/backend/shared_spec'
15
+
16
+ Delayed::Worker.logger = Logger.new('/tmp/dj.log')
17
+ ENV['RAILS_ENV'] = 'test'
18
+
19
+ Delayed::Worker.backend = :test
20
+
21
+ # Add this directory so the ActiveSupport autoloading works
22
+ ActiveSupport::Dependencies.autoload_paths << File.dirname(__FILE__)
23
+
24
+ # Add this to simulate Railtie initializer being executed
25
+ ActionMailer::Base.send(:extend, Delayed::DelayMail)
26
+
27
+
28
+ # Used to test interactions between DJ and an ORM
29
+ ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
30
+ ActiveRecord::Base.logger = Delayed::Worker.logger
31
+ ActiveRecord::Migration.verbose = false
32
+
33
+ ActiveRecord::Schema.define do
34
+ create_table :stories, :primary_key => :story_id, :force => true do |table|
35
+ table.string :text
36
+ table.boolean :scoped, :default => true
37
+ end
38
+ end
39
+
40
+ class Story < ActiveRecord::Base
41
+ self.primary_key = 'story_id'
42
+ def tell; text; end
43
+ def whatever(n, _); tell*n; end
44
+ default_scope where(:scoped => true)
45
+
46
+ handle_asynchronously :whatever
47
+ end
48
+
49
+ RSpec.configure do |config|
50
+ config.after(:each) do
51
+ Delayed::Worker.reset
52
+ end
53
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Delayed::Backend::Test::Job do
4
+ it_should_behave_like 'a delayed_job backend'
5
+
6
+ describe "#reload" do
7
+ it 'should cause the payload object to be reloaded' do
8
+ job = "foo".delay.length
9
+ o = job.payload_object
10
+ o.object_id.should_not == job.reload.payload_object.object_id
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Delayed::Worker do
4
+ describe "backend=" do
5
+ before do
6
+ @clazz = Class.new
7
+ Delayed::Worker.backend = @clazz
8
+ end
9
+
10
+ it "should set the Delayed::Job constant to the backend" do
11
+ Delayed::Job.should == @clazz
12
+ end
13
+
14
+ it "should set backend with a symbol" do
15
+ Delayed::Worker.backend = :test
16
+ Delayed::Worker.backend.should == Delayed::Backend::Test::Job
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe "YAML" do
4
+ it "should autoload classes" do
5
+ lambda {
6
+ yaml = "--- !ruby/class Autoloaded::Clazz\n"
7
+ YAML.load(yaml).should == Autoloaded::Clazz
8
+ }.should_not raise_error
9
+ end
10
+
11
+ it "should autoload the class of a struct" do
12
+ lambda {
13
+ yaml = "--- !ruby/class Autoloaded::Struct\n"
14
+ YAML.load(yaml).should == Autoloaded::Struct
15
+ }.should_not raise_error
16
+ end
17
+
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
30
+ end
31
+
32
+ it "should not throw an uninitialized constant Syck::Syck when using YAML.load_file with poorly formed yaml" do
33
+ lambda {
34
+ YAML.load_file(File.expand_path('spec/fixtures/bad_alias.yml'))
35
+ }.should_not raise_error
36
+ end
37
+
38
+ it "should not throw an uninitialized constant Syck::Syck when using YAML.load with poorly formed yaml" do
39
+ lambda { YAML.load(YAML.dump("foo: *bar"))}.should_not raise_error
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,214 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: drewda_delayed_job
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matt Griffin
9
+ - Brian Ryckbost
10
+ - Steve Richert
11
+ - Chris Gaffney
12
+ - Brandon Keepers
13
+ - Tobias Lütke
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+ date: 2012-05-29 00:00:00.000000000 Z
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: activesupport
21
+ requirement: !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ type: :runtime
28
+ prerelease: false
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '3.0'
35
+ - !ruby/object:Gem::Dependency
36
+ name: activerecord
37
+ requirement: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ version: '3.0'
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ~>
49
+ - !ruby/object:Gem::Version
50
+ version: '3.0'
51
+ - !ruby/object:Gem::Dependency
52
+ name: actionmailer
53
+ requirement: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ version: '3.0'
59
+ type: :development
60
+ prerelease: false
61
+ version_requirements: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: '3.0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rspec
69
+ requirement: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ version: '2.0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: simplecov
101
+ requirement: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ description: ! 'Delayed_job (or DJ) encapsulates the common pattern of asynchronously
116
+ executing longer tasks in the background. It is a direct extraction from Shopify
117
+ where the job table is responsible for a multitude of core tasks.
118
+
119
+
120
+ This gem is collectiveidea''s fork (http://github.com/collectiveidea/delayed_job).'
121
+ email:
122
+ - brian@collectiveidea.com
123
+ executables: []
124
+ extensions: []
125
+ extra_rdoc_files:
126
+ - README.textile
127
+ files:
128
+ - contrib/delayed_job.monitrc
129
+ - contrib/delayed_job_multiple.monitrc
130
+ - lib/delayed/backend/base.rb
131
+ - lib/delayed/backend/shared_spec.rb
132
+ - lib/delayed/command.rb
133
+ - lib/delayed/deserialization_error.rb
134
+ - lib/delayed/lifecycle.rb
135
+ - lib/delayed/message_sending.rb
136
+ - lib/delayed/performable_mailer.rb
137
+ - lib/delayed/performable_method.rb
138
+ - lib/delayed/plugin.rb
139
+ - lib/delayed/plugins/clear_locks.rb
140
+ - lib/delayed/psych_ext.rb
141
+ - lib/delayed/railtie.rb
142
+ - lib/delayed/recipes.rb
143
+ - lib/delayed/serialization/active_record.rb
144
+ - lib/delayed/syck_ext.rb
145
+ - lib/delayed/tasks.rb
146
+ - lib/delayed/worker.rb
147
+ - lib/delayed/yaml_ext.rb
148
+ - lib/delayed_job.rb
149
+ - lib/generators/delayed_job/delayed_job_generator.rb
150
+ - lib/generators/delayed_job/templates/script
151
+ - recipes/delayed_job.rb
152
+ - spec/autoloaded/clazz.rb
153
+ - spec/autoloaded/instance_clazz.rb
154
+ - spec/autoloaded/instance_struct.rb
155
+ - spec/autoloaded/struct.rb
156
+ - spec/delayed/backend/test.rb
157
+ - spec/delayed/serialization/test.rb
158
+ - spec/fixtures/bad_alias.yml
159
+ - spec/lifecycle_spec.rb
160
+ - spec/message_sending_spec.rb
161
+ - spec/performable_mailer_spec.rb
162
+ - spec/performable_method_spec.rb
163
+ - spec/sample_jobs.rb
164
+ - spec/spec_helper.rb
165
+ - spec/test_backend_spec.rb
166
+ - spec/worker_spec.rb
167
+ - spec/yaml_ext_spec.rb
168
+ - MIT-LICENSE
169
+ - README.textile
170
+ homepage: http://github.com/collectiveidea/delayed_job
171
+ licenses: []
172
+ post_install_message:
173
+ rdoc_options:
174
+ - --main
175
+ - README.textile
176
+ - --inline-source
177
+ - --line-numbers
178
+ require_paths:
179
+ - lib
180
+ required_ruby_version: !ruby/object:Gem::Requirement
181
+ none: false
182
+ requirements:
183
+ - - ! '>='
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ required_rubygems_version: !ruby/object:Gem::Requirement
187
+ none: false
188
+ requirements:
189
+ - - ! '>='
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 1.8.24
195
+ signing_key:
196
+ specification_version: 3
197
+ summary: Database-backed asynchronous priority queue system -- Extracted from Shopify
198
+ test_files:
199
+ - spec/autoloaded/clazz.rb
200
+ - spec/autoloaded/instance_clazz.rb
201
+ - spec/autoloaded/instance_struct.rb
202
+ - spec/autoloaded/struct.rb
203
+ - spec/delayed/backend/test.rb
204
+ - spec/delayed/serialization/test.rb
205
+ - spec/fixtures/bad_alias.yml
206
+ - spec/lifecycle_spec.rb
207
+ - spec/message_sending_spec.rb
208
+ - spec/performable_mailer_spec.rb
209
+ - spec/performable_method_spec.rb
210
+ - spec/sample_jobs.rb
211
+ - spec/spec_helper.rb
212
+ - spec/test_backend_spec.rb
213
+ - spec/worker_spec.rb
214
+ - spec/yaml_ext_spec.rb