chronofage 0.0.8 → 0.0.9

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: dd3bad90d7edae25dc63743e6bd15d1e4c831d18
4
- data.tar.gz: fbe2f8a8f86bea66d8c6dce3fdef997b913185d6
3
+ metadata.gz: 77dd2e709fcf6a264c35626d40beedfcdd2d3cd6
4
+ data.tar.gz: 726fd2120e7c40be39075d604af5cbbcbcf8f6a8
5
5
  SHA512:
6
- metadata.gz: 0a1f512858957f919f0e92bcf8b003d20b4a769ba22c8385028ad136d1b0655a0301a2d4bacb414f0d67d33ffc7d50058c6e8e33e328894d0f21200a867b8d28
7
- data.tar.gz: b6a80888084d2bf322bf763fa466237ad1b0ddd8a7fb75bd6e37dcb17815626cde0a671add86bbe1368227628173846617978156c1c143d0a00be385052039a5
6
+ metadata.gz: 8c2180287e87f045dbd3d9c53dc6148832041efd41b91ba9ad5a513cda6dfb48bd282c37d28662c4cb9c1207941ce43d50a90e0a8420942366589d7447d6fc0d
7
+ data.tar.gz: 7c78d45dcdaad24cfdbfa3fd27012ee22951854d8f40090e27941d7aa8bbb23ff836dfd8a9c4fe7f6dfe348b6020ebe4c0c9b56b62c59eb3208d7182c7584a02
@@ -5,12 +5,17 @@ module Chronofage
5
5
  scope :ready, -> { where(started_at: nil) }
6
6
  scope :started, -> { where.not(started_at: nil).where(failed_at: nil, completed_at: nil) }
7
7
 
8
- def self.next(queue_name)
9
- ready.where(queue_name: queue_name).order(priority: :asc).first
8
+ def self.take_next(queue_name, concurrency)
9
+ ActiveRecord::Base.transaction do
10
+ ActiveRecord::Base.connection.execute('LOCK chronofage_jobs IN ACCESS EXCLUSIVE MODE')
11
+
12
+ ready.where(queue_name: queue_name).order(priority: :asc).first.tap do |job|
13
+ job.started! if job.present? && job.concurrents.count < concurrency
14
+ end
15
+ end
10
16
  end
11
17
 
12
18
  def perform
13
- started!
14
19
  output = ActiveJob::Base.execute(job_data)
15
20
  completed!(output)
16
21
  rescue Exception => error
@@ -1,3 +1,3 @@
1
1
  module Chronofage
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -1,10 +1,8 @@
1
1
  namespace :chronofage_engine do
2
2
  namespace :jobs do
3
3
  task :execute, [:queue_name, :concurrency] => :environment do |t, args|
4
- job = Chronofage::Job.next(args.queue_name)
5
- if job.present? && job.concurrents.count < args.concurrency.to_i
6
- job.perform
7
- end
4
+ job = Chronofage::Job.take_next(args.queue_name, args.concurrency.to_i)
5
+ job.perform if job.present?
8
6
  end
9
7
  end
10
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chronofage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Goya
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-01-05 00:00:00.000000000 Z
12
+ date: 2018-03-29 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Cron based job scheduler
15
15
  email:
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  version: '0'
54
54
  requirements: []
55
55
  rubyforge_project:
56
- rubygems_version: 2.5.2
56
+ rubygems_version: 2.5.2.1
57
57
  signing_key:
58
58
  specification_version: 4
59
59
  summary: Cron based job scheduler