async-job 0.6.0 → 0.7.1

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
  SHA256:
3
- metadata.gz: 6aa1dbd39e225aaa055f15ffb7976669c500ce4e6a803262356f47ad026a826b
4
- data.tar.gz: c594059b63317a346fac7b7780ea99f633ab2f94c9bd20ede9bdd80c2b310f47
3
+ metadata.gz: 5168ca3167c401c68ffca433ef65962420641cd4826e1d1fb9e4700bf5c9a5c8
4
+ data.tar.gz: da6da3de6436cc9c1ade6523610033c683bafff75aa84640b12826b7d95cacfe
5
5
  SHA512:
6
- metadata.gz: 73f4fe066ea17811d637a00592b34dc51c350287e1ffe7f73e7ae98dd3413800685804ec70b1038eca718ee353d36c41afcaf77752ed237c726aadff60545a2d
7
- data.tar.gz: b9e0dc1720b5f4bc8eb920a265e41a8a95bcdcf3db2694fdfd358fe9a62d3752b371c680acefebf1bfb12012e50440e216139725888391580180b4dc79de059e
6
+ metadata.gz: 3fb44c033b61704b4b5cb2d0b6ad2351d71c35d2f63c96efca439478c75e404e80e31caa91fe291d07e537bb3bd47d1114153071d49f78c7a33fc14e6ab6cab2
7
+ data.tar.gz: 8371e91c27a9701cf34dacf575596c9af03dbbaa188837df5a6e90d9110f80d54056cd757b399a0e715f2a6268e128c7ee346dd2634fae40bd83f031f3bf7ad5
checksums.yaml.gz.sig CHANGED
Binary file
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2024, by Samuel Williams.
5
+
6
+ require 'console/event/failure'
7
+
8
+ module Async
9
+ module Job
10
+ module Backend
11
+ module Aggregate
12
+ class Server
13
+ def initialize(delegate, parent: nil)
14
+ @delegate = delegate
15
+
16
+ @task = nil
17
+ @ready = Async::Condition.new
18
+
19
+ @pending = Array.new
20
+ @processing = Array.new
21
+ end
22
+
23
+ def flush(jobs)
24
+ while job = jobs.shift
25
+ @delegate.call(job)
26
+ end
27
+ rescue => error
28
+ Console::Event::Failure.for(error).emit(self, "Could not flush #{jobs.size} jobs.")
29
+ end
30
+
31
+ def run(task)
32
+ while true
33
+ while @pending.empty?
34
+ @ready.wait
35
+ end
36
+
37
+ task.defer_stop do
38
+ # Swap the buffers:
39
+ @pending, @processing = @processing, @pending
40
+
41
+ flush(@processing)
42
+ end
43
+ end
44
+ end
45
+
46
+ # Start the background processing task if it is not already running.
47
+ #
48
+ # @return [Boolean] true if the task was started, false if it was already running.
49
+ protected def start!(parent: Async::Task.current)
50
+ return false if @task
51
+
52
+ # We are creating a task:
53
+ @task = true
54
+
55
+ parent.async(transient: true, annotation: self.class.name) do |task|
56
+ @task = task
57
+
58
+ run(task)
59
+ ensure
60
+ # Ensure that all jobs are flushed before we exit:
61
+ flush(@processing) if @processing.any?
62
+ flush(@pending) if @pending.any?
63
+ @task = nil
64
+ end
65
+
66
+ return true
67
+ end
68
+
69
+ # Enqueue a job into the pending buffer.
70
+ #
71
+ # Start the background processing task if it is not already running.
72
+ def call(job)
73
+ @pending << job
74
+
75
+ start! or @ready.signal
76
+ end
77
+
78
+ def stop
79
+ @task&.stop
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2024, by Samuel Williams.
5
+
6
+ require_relative 'aggregate/server'
7
+
8
+ module Async
9
+ module Job
10
+ module Backend
11
+ module Aggregate
12
+ def self.new(delegate)
13
+ return Server.new(delegate)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -13,6 +13,10 @@ module Async
13
13
  @delegate = delegate
14
14
  end
15
15
 
16
+ def empty?
17
+ @jobs.empty?
18
+ end
19
+
16
20
  attr :jobs
17
21
 
18
22
  def call(job)
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Async
7
7
  module Job
8
- VERSION = "0.6.0"
8
+ VERSION = "0.7.1"
9
9
  end
10
10
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-job
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -38,7 +38,7 @@ cert_chain:
38
38
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
39
39
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
40
40
  -----END CERTIFICATE-----
41
- date: 2024-08-02 00:00:00.000000000 Z
41
+ date: 2024-08-08 00:00:00.000000000 Z
42
42
  dependencies:
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: async
@@ -76,6 +76,8 @@ extra_rdoc_files: []
76
76
  files:
77
77
  - lib/async/job.rb
78
78
  - lib/async/job/backend.rb
79
+ - lib/async/job/backend/aggregate.rb
80
+ - lib/async/job/backend/aggregate/server.rb
79
81
  - lib/async/job/backend/inline.rb
80
82
  - lib/async/job/backend/inline/server.rb
81
83
  - lib/async/job/backend/redis.rb
@@ -114,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
116
  - !ruby/object:Gem::Version
115
117
  version: '0'
116
118
  requirements: []
117
- rubygems_version: 3.5.11
119
+ rubygems_version: 3.5.13
118
120
  signing_key:
119
121
  specification_version: 4
120
122
  summary: A asynchronous job queue for Ruby.
metadata.gz.sig CHANGED
Binary file