delayed_job_active_record 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,4 +1,9 @@
1
- # DelayedJob ActiveRecord Backend [![Build Status](https://travis-ci.org/collectiveidea/delayed_job_active_record.png)](https://travis-ci.org/collectiveidea/delayed_job_active_record) [![Dependency Status](https://gemnasium.com/collectiveidea/delayed_job_active_record.png)](https://gemnasium.com/collectiveidea/delayed_job_active_record)
1
+ # DelayedJob ActiveRecord Backend
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/delayed_job_active_record.png)](https://rubygems.org/gems/delayed_job_active_record)
4
+ [![Build Status](https://travis-ci.org/collectiveidea/delayed_job_active_record.png)](https://travis-ci.org/collectiveidea/delayed_job_active_record)
5
+ [![Dependency Status](https://gemnasium.com/collectiveidea/delayed_job_active_record.png)](https://gemnasium.com/collectiveidea/delayed_job_active_record)
6
+ [![Code Climate](https://codeclimate.com/github/collectiveidea/delayed_job_active_record.png)](https://codeclimate.com/github/collectiveidea/delayed_job_active_record)
2
7
 
3
8
  ## Installation
4
9
 
@@ -8,14 +13,16 @@ Add the gem to your Gemfile:
8
13
 
9
14
  Run `bundle install`.
10
15
 
11
- If you're using Rails, run the generator to create the migration for the delayed_job table.
16
+ If you're using Rails, run the generator to create the migration for the
17
+ delayed_job table.
12
18
 
13
19
  rails g delayed_job:active_record
14
20
  rake db:migrate
15
21
 
16
22
  ## Upgrading from 2.x to 3.0.0
17
23
 
18
- If you're upgrading from Delayed Job 2.x, run the upgrade generator to create a migration to add a column to your delayed_jobs table.
24
+ If you're upgrading from Delayed Job 2.x, run the upgrade generator to create a
25
+ migration to add a column to your delayed_jobs table.
19
26
 
20
27
  rails g delayed_job:upgrade
21
28
  rake db:migrate
@@ -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 = '0.4.0'
18
+ spec.version = '0.4.1'
19
19
  end
@@ -44,26 +44,27 @@ module Delayed
44
44
  # scope to filter to records that are "ready to run"
45
45
  readyScope = self.ready_to_run(worker.name, max_run_time)
46
46
 
47
- # scope to filter to the single next eligible job (locking it for update http://www.postgresql.org/docs/9.0/static/sql-select.html#SQL-FOR-UPDATE-SHARE)
47
+ # scope to filter to the single next eligible job
48
48
  nextScope = readyScope.scoped
49
49
  nextScope = nextScope.scoped(:conditions => ['priority >= ?', Worker.min_priority]) if Worker.min_priority
50
50
  nextScope = nextScope.scoped(:conditions => ['priority <= ?', Worker.max_priority]) if Worker.max_priority
51
51
  nextScope = nextScope.scoped(:conditions => ["queue IN (?)", Worker.queues]) if Worker.queues.any?
52
- nextScope = nextScope.scoped.by_priority.limit(1).lock(true)
53
- nextScope = nextScope.scoped.select('id')
52
+ nextScope = nextScope.scoped.by_priority.limit(1)
54
53
 
55
54
  now = self.db_time_now
56
55
 
57
56
  if ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
58
- # This works on PostgreSQL and uses 1 less query, but uses SQL not supported nativly through ActiveRecord
57
+ # Custom SQL required for PostgreSQL because postgres does not support UPDATE...LIMIT
58
+ # This locks the single record 'FOR UPDATE' in the subquery (http://www.postgresql.org/docs/9.0/static/sql-select.html#SQL-FOR-UPDATE-SHARE)
59
+ # Note: active_record would attempt to generate UPDATE...LIMIT like sql for postgres if we use a .limit() filter, but it would not use
60
+ # 'FOR UPDATE' and we would have many locking conflicts
59
61
  quotedTableName = ::ActiveRecord::Base.connection.quote_column_name(self.table_name)
60
- reserved = self.find_by_sql(["UPDATE #{quotedTableName} SET locked_at = ?, locked_by = ? WHERE id IN (#{nextScope.to_sql}) RETURNING *",now,worker.name])
62
+ subquerySql = nextScope.lock(true).select('id').to_sql
63
+ reserved = self.find_by_sql(["UPDATE #{quotedTableName} SET locked_at = ?, locked_by = ? WHERE id IN (#{subquerySql}) RETURNING *",now,worker.name])
61
64
  return reserved[0]
62
65
  else
63
- # This works on any database and uses seperate queries to lock and return the job
64
- # Databases like PostgreSQL and MySQL that support "SELECT .. FOR UPDATE" (ActiveRecord Pessimistic locking) don't need the second application
65
- # of 'readyScope' but it doesn't hurt and it ensures that the job being locked still meets ready_to_run criteria.
66
- count = readyScope.where(:id => nextScope).update_all(:locked_at => now, :locked_by => worker.name)
66
+ # This works on MySQL and other DBs that support UPDATE...LIMIT. It uses separate queries to lock and return the job
67
+ count = nextScope.update_all(:locked_at => now, :locked_by => worker.name)
67
68
  return nil if count == 0
68
69
  return self.where(:locked_at => now, :locked_by => worker.name).first
69
70
  end
data/spec/database.yml CHANGED
@@ -1,8 +1,14 @@
1
- sqlite:
2
- adapter: sqlite3
3
- database: ":memory:"
4
-
5
1
  mysql:
6
2
  adapter: mysql
7
- database: delayed_job
8
- uesrname: root
3
+ database: delayed_job_test
4
+ username: root
5
+ encoding: utf8
6
+
7
+ postgresql:
8
+ adapter: postgresql
9
+ database: delayed_job_test
10
+ username: postgres
11
+
12
+ sqlite3:
13
+ adapter: sqlite3
14
+ database: ":memory:"
data/spec/spec_helper.rb CHANGED
@@ -12,7 +12,8 @@ Delayed::Worker.logger = Logger.new('/tmp/dj.log')
12
12
  ENV['RAILS_ENV'] = 'test'
13
13
 
14
14
  config = YAML.load(File.read('spec/database.yml'))
15
- ActiveRecord::Base.establish_connection config['sqlite']
15
+ db_adapter = ENV['CI_DB_ADAPTER'] || 'sqlite3'
16
+ ActiveRecord::Base.establish_connection config[db_adapter]
16
17
  ActiveRecord::Base.logger = Delayed::Worker.logger
17
18
  ActiveRecord::Migration.verbose = false
18
19
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_job_active_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-02-10 00:00:00.000000000 Z
14
+ date: 2013-02-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activerecord
@@ -91,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
91
  version: '0'
92
92
  segments:
93
93
  - 0
94
- hash: -1678145937006917333
94
+ hash: -3937611050196962247
95
95
  required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  none: false
97
97
  requirements:
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  segments:
102
102
  - 0
103
- hash: -1678145937006917333
103
+ hash: -3937611050196962247
104
104
  requirements: []
105
105
  rubyforge_project:
106
106
  rubygems_version: 1.8.23