chronofage 0.0.11 → 0.0.13

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
- SHA1:
3
- metadata.gz: ee0775738a92e85081cbd4afc18c66c94423f3f7
4
- data.tar.gz: 816e76884914b74ce4b02e8a0136f2e3be36b460
2
+ SHA256:
3
+ metadata.gz: 00a1b933b3475c55e9261d46f3cf75b15aa5dd5633c631ee3575661afdbde825
4
+ data.tar.gz: 0f19dd4fcbc79dfdf337074a53f1d89c20557f4c6b1d273cd30e36223baefbd5
5
5
  SHA512:
6
- metadata.gz: cba9f3f8749cbbd31cf7cd337be47e9b0d4bbecd7804d7ce09b7afab4c34811db96185b9ef5b6c359dc97f97341994862761ad5a514119c93f3a86867ac95b17
7
- data.tar.gz: 726e890335bc5080b024b0e0c025ff69511dadd25d0347d25357b18452dae849913c6741e32969c70cfd09a8913042e3e355b092fbba3225f0defbcc04043575
6
+ metadata.gz: b7bfef5758997d659e6bbc3867a1bb048b857464471394cc8643bf012dc932f1fbb78884255b34bc42d93f5c5a8614f864ef9ec88cb542a16ff5adaf738dcce6
7
+ data.tar.gz: 20c4b24bb82dc453c2e763c92276288db870cb474e3f03e085466274c1911568d8a9dc95243235da3c6a5ef95ec1f4f8f6d8776bc36be01f2798035537a47927
data/README.md CHANGED
@@ -57,3 +57,9 @@ of 6 jobs, 2 for each host, and check for new jobs every 5 minutes.
57
57
  ```
58
58
  */5 * * * * cd /var/www/my_app && rake chronofage_engine:jobs:execute[heavy,2]
59
59
  ```
60
+
61
+ You can also make Chronofage poll the database for new jobs to execute, this solution is way more reactive.
62
+
63
+ ```
64
+ rake chronofage_engine:jobs:poll[heavy,2]
65
+ ```
@@ -5,12 +5,12 @@ 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.take_next(queue_name, concurrency)
8
+ def self.take_next(queue_name, concurrency, global_concurrency)
9
9
  ActiveRecord::Base.transaction do
10
10
  ActiveRecord::Base.connection.execute('LOCK chronofage_jobs IN ACCESS EXCLUSIVE MODE')
11
11
 
12
12
  job = ready.where(queue_name: queue_name).order(priority: :asc).first
13
- if job.present? && job.concurrents.count < concurrency
13
+ if job.present? && job.concurrents.count < concurrency && (global_concurrency == 0 || job.global_concurrents.count < global_concurrency)
14
14
  job.started!
15
15
  job
16
16
  else
@@ -64,7 +64,11 @@ module Chronofage
64
64
  end
65
65
 
66
66
  def concurrents
67
- Chronofage::Job.started.where(queue_name: queue_name, host: Chronofage::Job.host)
67
+ global_concurrents.where(host: Chronofage::Job.host)
68
+ end
69
+
70
+ def global_concurrents
71
+ Chronofage::Job.started.where(queue_name: queue_name)
68
72
  end
69
73
 
70
74
  def state
@@ -1,3 +1,3 @@
1
1
  module Chronofage
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.13"
3
3
  end
@@ -1,8 +1,30 @@
1
1
  namespace :chronofage_engine do
2
2
  namespace :jobs do
3
- task :execute, [:queue_name, :concurrency] => :environment do |t, args|
4
- job = Chronofage::Job.take_next(args.queue_name, args.concurrency.to_i)
3
+ task :execute, [:queue_name, :concurrency, :global_concurrency] => :environment do |t, args|
4
+ job = Chronofage::Job.take_next(args.queue_name, args.concurrency.to_i, args.global_concurrency.to_i)
5
5
  job.perform if job.present?
6
6
  end
7
+
8
+ task :poll, [:queue_name, :concurrency, :global_concurrency] => :environment do |t, args|
9
+ loop do
10
+ job = Chronofage::Job.take_next(args.queue_name, args.concurrency.to_i, args.global_concurrency.to_i)
11
+ if job.blank?
12
+ sleep 1
13
+ next
14
+ end
15
+
16
+ ActiveRecord::Base.connection.disconnect!
17
+
18
+ pid = fork do
19
+ Process.daemon
20
+
21
+ ActiveRecord::Base.establish_connection
22
+ job.perform
23
+ end
24
+ Process.detach(pid)
25
+
26
+ ActiveRecord::Base.establish_connection
27
+ end
28
+ end
7
29
  end
8
30
  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.11
4
+ version: 0.0.13
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-03-29 00:00:00.000000000 Z
12
+ date: 2019-07-09 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Cron based job scheduler
15
15
  email:
@@ -52,8 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  requirements: []
55
- rubyforge_project:
56
- rubygems_version: 2.5.2.1
55
+ rubygems_version: 3.0.3
57
56
  signing_key:
58
57
  specification_version: 4
59
58
  summary: Cron based job scheduler