delayed_job_active_record 4.0.0.beta2 → 4.0.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Rakefile +30 -7
- data/delayed_job_active_record.gemspec +2 -2
- data/lib/delayed/backend/active_record.rb +17 -1
- data/lib/generators/delayed_job/active_record_generator.rb +2 -0
- data/lib/generators/delayed_job/next_migration_version.rb +14 -0
- data/lib/generators/delayed_job/templates/migration.rb +9 -9
- data/lib/generators/delayed_job/upgrade_generator.rb +2 -1
- data/spec/delayed/backend/active_record_spec.rb +17 -0
- data/spec/helper.rb +13 -2
- metadata +22 -24
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YjhkN2JjN2FiYWVkMTM0ZWRlMjA4NjBiZWE2NjZmYWM5YzNkZTJjZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NDFiNDA5ZTQ5MTA3ZmU3NWJmMzkzMWFhNWU4MGZmMjM1MjJkOGRmMQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
N2FhMjcwZTBmMzkyNWEzMTg0MjhlMDY1NmExNzU2NGUyMjM2MzgzMDVjMTlk
|
10
|
+
MjIzMDE4YTQ3MWYwZjNjZmY4NDc2MzA1MzlmMzBkNTZjYmY0YzE3NzI1ZmY2
|
11
|
+
NjVmZjMwZDExNjdkNDhlNDYyMjE3ZmFhMThiODk4YjRlNDNjYTc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YTdjMGVhMWM1MjM5OTE5NzI1ZmZiYjlkNjcxNTg2ODkzYzRlZWQ5ZWQ4Y2I2
|
14
|
+
MzE1NmNjZWY3NDdiM2JmYTc4Y2RkMDJkNmM3ZWI0NDJlMjU1MTUyNjA0YWI5
|
15
|
+
NGZkNGE3M2U5NGI1YWQ1MzA5ODMwYzAyODA5Y2RjZDQxODlkZTE=
|
data/Rakefile
CHANGED
@@ -1,12 +1,35 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
require
|
3
|
-
require 'bundler/setup'
|
2
|
+
require "bundler/gem_helper"
|
4
3
|
Bundler::GemHelper.install_tasks
|
5
4
|
|
6
|
-
require
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
require "rspec/core/rake_task"
|
6
|
+
|
7
|
+
ADAPTERS = %w(mysql postgresql sqlite3)
|
8
|
+
|
9
|
+
ADAPTERS.each do |adapter|
|
10
|
+
desc "Run RSpec code examples for #{adapter} adapter"
|
11
|
+
RSpec::Core::RakeTask.new(adapter => "#{adapter}:adapter")
|
12
|
+
|
13
|
+
namespace adapter do
|
14
|
+
task :adapter do
|
15
|
+
ENV["ADAPTER"] = adapter
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
task :coverage do
|
21
|
+
ENV["COVERAGE"] = "true"
|
22
|
+
end
|
23
|
+
|
24
|
+
task :adapter do
|
25
|
+
ENV["ADAPTER"] = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
Rake::Task[:spec].enhance do
|
29
|
+
require "simplecov"
|
30
|
+
require "coveralls"
|
31
|
+
|
32
|
+
Coveralls::SimpleCov::Formatter.new.format(SimpleCov.result)
|
10
33
|
end
|
11
34
|
|
12
|
-
task :
|
35
|
+
task default: ([:coverage] + ADAPTERS + [:adapter])
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.add_dependency 'activerecord', ['>= 3.0', '< 4.1']
|
5
|
-
spec.add_dependency 'delayed_job', '
|
5
|
+
spec.add_dependency 'delayed_job', ['>= 3.0', '< 4.1']
|
6
6
|
spec.authors = ["Brian Ryckbost", "Matt Griffin", "Erik Michaels-Ober"]
|
7
7
|
spec.description = 'ActiveRecord backend for Delayed::Job, originally authored by Tobias Lütke'
|
8
8
|
spec.email = ['bryckbost@gmail.com', 'matt@griffinonline.org', 'sferik@gmail.com']
|
@@ -15,5 +15,5 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.require_paths = ['lib']
|
16
16
|
spec.summary = 'ActiveRecord backend for DelayedJob'
|
17
17
|
spec.test_files = Dir.glob("spec/**/*")
|
18
|
-
spec.version = '4.0.0.
|
18
|
+
spec.version = '4.0.0.beta3'
|
19
19
|
end
|
@@ -7,6 +7,11 @@ module Delayed
|
|
7
7
|
class Job < ::ActiveRecord::Base
|
8
8
|
include Delayed::Backend::Base
|
9
9
|
|
10
|
+
if ::ActiveRecord::VERSION::MAJOR < 4 || defined?(::ActiveRecord::MassAssignmentSecurity)
|
11
|
+
attr_accessible :priority, :run_at, :queue, :payload_object,
|
12
|
+
:failed_at, :locked_at, :locked_by, :handler
|
13
|
+
end
|
14
|
+
|
10
15
|
scope :by_priority, lambda { order('priority ASC, run_at ASC') }
|
11
16
|
|
12
17
|
before_save :set_default_run_at
|
@@ -62,7 +67,18 @@ module Delayed
|
|
62
67
|
# This works on MySQL and possibly some other DBs that support UPDATE...LIMIT. It uses separate queries to lock and return the job
|
63
68
|
count = ready_scope.limit(1).update_all(:locked_at => now, :locked_by => worker.name)
|
64
69
|
return nil if count == 0
|
65
|
-
self.where(:locked_at => now, :locked_by => worker.name).first
|
70
|
+
self.where(:locked_at => now, :locked_by => worker.name, :failed_at => nil).first
|
71
|
+
when "MSSQL"
|
72
|
+
# The MSSQL driver doesn't generate a limit clause when update_all is called directly
|
73
|
+
subsubquery_sql = ready_scope.limit(1).to_sql
|
74
|
+
# select("id") doesn't generate a subquery, so force a subquery
|
75
|
+
subquery_sql = "SELECT id FROM (#{subsubquery_sql}) AS x"
|
76
|
+
quoted_table_name = self.connection.quote_table_name(self.table_name)
|
77
|
+
sql = ["UPDATE #{quoted_table_name} SET locked_at = ?, locked_by = ? WHERE id IN (#{subquery_sql})", now, worker.name]
|
78
|
+
count = self.connection.execute(sanitize_sql(sql))
|
79
|
+
return nil if count == 0
|
80
|
+
# MSSQL JDBC doesn't support OUTPUT INSERTED.* for returning a result set, so query locked row
|
81
|
+
self.where(:locked_at => now, :locked_by => worker.name, :failed_at => nil).first
|
66
82
|
else
|
67
83
|
# This is our old fashion, tried and true, but slower lookup
|
68
84
|
ready_scope.limit(worker.read_ahead).detect do |job|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'generators/delayed_job/delayed_job_generator'
|
2
|
+
require 'generators/delayed_job/next_migration_version'
|
2
3
|
require 'rails/generators/migration'
|
3
4
|
require 'rails/generators/active_record'
|
4
5
|
|
@@ -6,6 +7,7 @@ require 'rails/generators/active_record'
|
|
6
7
|
module DelayedJob
|
7
8
|
class ActiveRecordGenerator < ::DelayedJobGenerator
|
8
9
|
include Rails::Generators::Migration
|
10
|
+
extend NextMigrationVersion
|
9
11
|
|
10
12
|
self.source_paths << File.join(File.dirname(__FILE__), 'templates')
|
11
13
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module DelayedJob
|
2
|
+
module NextMigrationVersion
|
3
|
+
# while methods have moved around this has been the implementation
|
4
|
+
# since ActiveRecord 3.0
|
5
|
+
def next_migration_number(dirname)
|
6
|
+
next_migration_number = current_migration_number(dirname) + 1
|
7
|
+
if ActiveRecord::Base.timestamped_migrations
|
8
|
+
[Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
|
9
|
+
else
|
10
|
+
"%.3d" % next_migration_number
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
class CreateDelayedJobs < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
3
|
create_table :delayed_jobs, :force => true do |table|
|
4
|
-
table.integer :priority, :default => 0
|
5
|
-
table.integer :attempts, :default => 0
|
6
|
-
table.text :handler
|
7
|
-
table.text :last_error
|
8
|
-
table.datetime :run_at
|
9
|
-
table.datetime :locked_at
|
10
|
-
table.datetime :failed_at
|
11
|
-
table.string :locked_by
|
12
|
-
table.string :queue
|
4
|
+
table.integer :priority, :default => 0, :null => false # Allows some jobs to jump to the front of the queue
|
5
|
+
table.integer :attempts, :default => 0, :null => false # Provides for retries, but still fail eventually.
|
6
|
+
table.text :handler, :null => false # 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.string :queue # The name of the queue this job is in
|
13
13
|
table.timestamps
|
14
14
|
end
|
15
15
|
|
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'generators/delayed_job/delayed_job_generator'
|
2
|
+
require 'generators/delayed_job/next_migration_version'
|
2
3
|
require 'rails/generators/migration'
|
3
|
-
require 'rails/generators/active_record'
|
4
4
|
|
5
5
|
# Extend the DelayedJobGenerator so that it creates an AR migration
|
6
6
|
module DelayedJob
|
7
7
|
class UpgradeGenerator < ::DelayedJobGenerator
|
8
8
|
include Rails::Generators::Migration
|
9
|
+
extend NextMigrationVersion
|
9
10
|
|
10
11
|
self.source_paths << File.join(File.dirname(__FILE__), 'templates')
|
11
12
|
|
@@ -43,6 +43,23 @@ describe Delayed::Backend::ActiveRecord::Job do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
if ::ActiveRecord::VERSION::MAJOR < 4 || defined?(::ActiveRecord::MassAssignmentSecurity)
|
47
|
+
context "ActiveRecord::Base.send(:attr_accessible, nil)" do
|
48
|
+
before do
|
49
|
+
Delayed::Backend::ActiveRecord::Job.send(:attr_accessible, nil)
|
50
|
+
end
|
51
|
+
|
52
|
+
after do
|
53
|
+
Delayed::Backend::ActiveRecord::Job.send(:attr_accessible, *Delayed::Backend::ActiveRecord::Job.new.attributes.keys)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "is still accessible" do
|
57
|
+
job = Delayed::Backend::ActiveRecord::Job.enqueue :payload_object => EnqueueJobMod.new
|
58
|
+
expect(Delayed::Backend::ActiveRecord::Job.find(job.id).handler).to_not be_blank
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
46
63
|
context "ActiveRecord::Base.table_name_prefix" do
|
47
64
|
it "when prefix is not set, use 'delayed_jobs' as table name" do
|
48
65
|
::ActiveRecord::Base.table_name_prefix = nil
|
data/spec/helper.rb
CHANGED
@@ -10,14 +10,21 @@ SimpleCov.start
|
|
10
10
|
require 'logger'
|
11
11
|
require 'rspec'
|
12
12
|
|
13
|
+
begin
|
14
|
+
require 'protected_attributes'
|
15
|
+
rescue LoadError
|
16
|
+
end
|
13
17
|
require 'delayed_job_active_record'
|
14
18
|
require 'delayed/backend/shared_spec'
|
15
19
|
|
16
20
|
Delayed::Worker.logger = Logger.new('/tmp/dj.log')
|
17
21
|
ENV['RAILS_ENV'] = 'test'
|
18
22
|
|
23
|
+
db_adapter, gemfile = ENV["ADAPTER"], ENV["BUNDLE_GEMFILE"]
|
24
|
+
db_adapter ||= gemfile && gemfile[%r(gemfiles/(.*?)/)] && $1
|
25
|
+
db_adapter ||= 'sqlite3'
|
26
|
+
|
19
27
|
config = YAML.load(File.read('spec/database.yml'))
|
20
|
-
db_adapter = ENV['CI_DB_ADAPTER'] || 'sqlite3'
|
21
28
|
ActiveRecord::Base.establish_connection config[db_adapter]
|
22
29
|
ActiveRecord::Base.logger = Delayed::Worker.logger
|
23
30
|
ActiveRecord::Migration.verbose = false
|
@@ -46,7 +53,11 @@ end
|
|
46
53
|
|
47
54
|
# Purely useful for test cases...
|
48
55
|
class Story < ActiveRecord::Base
|
49
|
-
|
56
|
+
if ::ActiveRecord::VERSION::MAJOR < 4 && ActiveRecord::VERSION::MINOR < 2
|
57
|
+
set_primary_key :story_id
|
58
|
+
else
|
59
|
+
self.primary_key = :story_id
|
60
|
+
end
|
50
61
|
def tell; text; end
|
51
62
|
def whatever(n, _); tell*n; end
|
52
63
|
default_scope { where(:scoped => true) }
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delayed_job_active_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.0.
|
5
|
-
prerelease: 6
|
4
|
+
version: 4.0.0.beta3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Brian Ryckbost
|
@@ -11,12 +10,20 @@ authors:
|
|
11
10
|
autorequire:
|
12
11
|
bindir: bin
|
13
12
|
cert_chain: []
|
14
|
-
date: 2013-
|
13
|
+
date: 2013-05-28 00:00:00.000000000 Z
|
15
14
|
dependencies:
|
16
15
|
- !ruby/object:Gem::Dependency
|
16
|
+
prerelease: false
|
17
17
|
name: activerecord
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3.0'
|
23
|
+
- - <
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '4.1'
|
18
26
|
requirement: !ruby/object:Gem::Requirement
|
19
|
-
none: false
|
20
27
|
requirements:
|
21
28
|
- - ! '>='
|
22
29
|
- !ruby/object:Gem::Version
|
@@ -25,9 +32,10 @@ dependencies:
|
|
25
32
|
- !ruby/object:Gem::Version
|
26
33
|
version: '4.1'
|
27
34
|
type: :runtime
|
35
|
+
- !ruby/object:Gem::Dependency
|
28
36
|
prerelease: false
|
37
|
+
name: delayed_job
|
29
38
|
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
none: false
|
31
39
|
requirements:
|
32
40
|
- - ! '>='
|
33
41
|
- !ruby/object:Gem::Version
|
@@ -35,22 +43,15 @@ dependencies:
|
|
35
43
|
- - <
|
36
44
|
- !ruby/object:Gem::Version
|
37
45
|
version: '4.1'
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
name: delayed_job
|
40
46
|
requirement: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
47
|
requirements:
|
43
|
-
- -
|
48
|
+
- - ! '>='
|
44
49
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
46
|
-
|
47
|
-
prerelease: false
|
48
|
-
version_requirements: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ~>
|
50
|
+
version: '3.0'
|
51
|
+
- - <
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 4.
|
53
|
+
version: '4.1'
|
54
|
+
type: :runtime
|
54
55
|
description: ActiveRecord backend for Delayed::Job, originally authored by Tobias
|
55
56
|
Lütke
|
56
57
|
email:
|
@@ -69,6 +70,7 @@ files:
|
|
69
70
|
- lib/delayed/backend/active_record.rb
|
70
71
|
- lib/delayed_job_active_record.rb
|
71
72
|
- lib/generators/delayed_job/active_record_generator.rb
|
73
|
+
- lib/generators/delayed_job/next_migration_version.rb
|
72
74
|
- lib/generators/delayed_job/templates/migration.rb
|
73
75
|
- lib/generators/delayed_job/templates/upgrade_migration.rb
|
74
76
|
- lib/generators/delayed_job/upgrade_generator.rb
|
@@ -79,30 +81,26 @@ files:
|
|
79
81
|
homepage: http://github.com/collectiveidea/delayed_job_active_record
|
80
82
|
licenses:
|
81
83
|
- MIT
|
84
|
+
metadata: {}
|
82
85
|
post_install_message:
|
83
86
|
rdoc_options: []
|
84
87
|
require_paths:
|
85
88
|
- lib
|
86
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
90
|
requirements:
|
89
91
|
- - ! '>='
|
90
92
|
- !ruby/object:Gem::Version
|
91
93
|
version: '0'
|
92
|
-
segments:
|
93
|
-
- 0
|
94
|
-
hash: 1966467636289984878
|
95
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
-
none: false
|
97
95
|
requirements:
|
98
96
|
- - ! '>'
|
99
97
|
- !ruby/object:Gem::Version
|
100
98
|
version: 1.3.1
|
101
99
|
requirements: []
|
102
100
|
rubyforge_project:
|
103
|
-
rubygems_version:
|
101
|
+
rubygems_version: 2.0.3
|
104
102
|
signing_key:
|
105
|
-
specification_version:
|
103
|
+
specification_version: 4
|
106
104
|
summary: ActiveRecord backend for DelayedJob
|
107
105
|
test_files:
|
108
106
|
- spec/database.yml
|