simpleci-worker 0.1.2 → 0.1.3

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: e0160576a6f99b17570fd7e4105d4196df48b94b
4
- data.tar.gz: 01aca32edce7d70828f9e1f66cf68d2895e02dff
3
+ metadata.gz: 724b1852c4dec6537db709453b0ca9b3f0058fe8
4
+ data.tar.gz: ad2062d63d27371735b47baf59dc84aaa03ab04c
5
5
  SHA512:
6
- metadata.gz: 29f24fe261b00489c6a2628e401e2420e3c0734cc27e790ac6b185e82cc514e244cf1b1e20c782b9103979f6a92367685fc28a17dda732876c24952016e48104
7
- data.tar.gz: f9bd8109167221d6e5f88fcbca97f3090627d19121a695884d9e9585c291cb05dcba38d7996f88455168c5c6962dda6befeb246f48a0a87c9ada498c3490e121
6
+ metadata.gz: f3728a34c2ce129dc461a34b5cde6559bf57c707b2396b297047db9fb90d1c6d1eead50820fab9b02df6e8a8f27512b6836e1fd1564dd0663a4fe049b66f7849
7
+ data.tar.gz: 75ead4be80821aaeb335d945031cc71a9cfe0bb082eaa7de2379ce38b0a3cc670f55897f1d03ffce62a4611619480f2b4e68127989d0be70f24c8b88da23ce06
data/Gemfile CHANGED
@@ -4,4 +4,5 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'sqlite3'
7
+ gem 'mysql2'
7
8
  gem 'activerecord'
@@ -26,6 +26,8 @@ module Worker
26
26
  @poll_interval = opts[:poll_interval] || 5 # 5 second polling
27
27
  @log_backtrace = !!opts[:log_backtrace]
28
28
 
29
+ @db_adapter = db_config[:adapter]
30
+
29
31
  create_table
30
32
  end
31
33
 
@@ -61,10 +63,19 @@ module Worker
61
63
 
62
64
  # locks a set of jobs for this worker
63
65
  def dequeue
64
- query = db[:worker_jobs]
65
- .where(
66
- '`run_at` < ? AND `locked_by` IS NULL AND `id` in (SELECT `id` FROM `worker_jobs` ORDER BY `priority` DESC LIMIT ?)',
67
- Time.now, jobs_per_worker)
66
+
67
+ if @db_adapter == 'mysql2' || @db_adapter == 'mysql'
68
+ query = db[:worker_jobs]
69
+ .limit(jobs_per_worker)
70
+ .where('`run_at` < ?', Time.now)
71
+ .where('`locked_by` IS NULL')
72
+ .reverse_order('priority')
73
+ else
74
+ query = db[:worker_jobs]
75
+ .where(
76
+ '`run_at` < ? AND `locked_by` IS NULL AND `id` in (SELECT `id` FROM `worker_jobs` ORDER BY `priority` DESC LIMIT ?)',
77
+ Time.now, jobs_per_worker)
78
+ end
68
79
 
69
80
  if queue_name
70
81
  query = query.where(queue: queue_name)
@@ -1,3 +1,3 @@
1
1
  module Worker
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simpleci-worker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin Walker