async-job 0.2.1 → 0.3.0

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: 895f34561c4da96884e09c180b33ab7ed4ac52b5c72e10af70403deea920200e
4
- data.tar.gz: 8af66add606e0eebb5abfb5d35a67d1e41547c86227054a56fd1dbf1e2f90929
3
+ metadata.gz: 44a092dcad8310e5301d4c273e08c21a5eb046b530ff27cce0320fd56ccd3f8f
4
+ data.tar.gz: 11c40eb020b847b46a933d8ff2b1f27bb015edf781e4d4ca3a4579269140a8cb
5
5
  SHA512:
6
- metadata.gz: 5bd937f27dd026b2c6c3e44c2a2d801cd936c477fd1e514d0c34f07d0bc4db6cf7c3583ea26348a85277b33cc59bbd90ec1626bf67eb8bdac1b85eaca6b588ee
7
- data.tar.gz: 94a26598b246051666bf68c9cd1f11785ca75f32c43fb9d74349ad193650cd03df9cc7069d2b46f128b11cd50fc35383b0018d31acdceb833d013090ce711fc3
6
+ metadata.gz: 69d052fe00161a40300410b95aea22dde2a4b6eb41bc320d915e72327324bad175b0c1ca1dd4953287e069cbc6755d222fe2de5346acda3b34ff5f9818b9606a
7
+ data.tar.gz: 8087a4c82be53394574b1ab70affcdf3c5355a1db0c24f022ea012c771cc290d9a04d173e49cd10edd6b54d8a8aba1f0b78bc392124f9d401e6940452013d45f
checksums.yaml.gz.sig CHANGED
Binary file
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2024, by Samuel Williams.
5
+
6
+ module Async
7
+ module Job
8
+ module Backend
9
+ module Inline
10
+ class Server
11
+ def initialize(handler)
12
+ @handler = handler
13
+ end
14
+
15
+ def enqueue(job)
16
+ Async do
17
+ @handler.call(job)
18
+ end
19
+ end
20
+
21
+ def schedule(job, timestamp)
22
+ Async do
23
+ sleep(timestamp - Time.now)
24
+ @handler.call(job)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ 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 'inline/server'
7
+
8
+ module Async
9
+ module Job
10
+ module Backend
11
+ module Inline
12
+ def self.new(handler)
13
+ return Server.new(handler)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -15,7 +15,9 @@ module Async
15
15
  module Backend
16
16
  module Redis
17
17
  class Server
18
- def initialize(client, prefix)
18
+ def initialize(handler, client, prefix)
19
+ @handler = handler
20
+
19
21
  @id = SecureRandom.uuid
20
22
  @client = client
21
23
  @prefix = prefix
@@ -35,6 +37,10 @@ module Async
35
37
 
36
38
  # Start the processing queue, which will move jobs to the ready queue when they are abandoned:
37
39
  @processing_queue.start
40
+
41
+ while true
42
+ self.dequeue
43
+ end
38
44
  end
39
45
 
40
46
  def enqueue(job)
@@ -45,23 +51,19 @@ module Async
45
51
  @delayed_queue.add(job, timestamp, @job_store)
46
52
  end
47
53
 
48
- def process(&block)
54
+ protected
55
+
56
+ def dequeue
49
57
  id = @processing_queue.fetch
50
58
  begin
51
59
  job = @job_store.get(id)
52
- yield id, job
60
+ @handler.call(job)
53
61
  @processing_queue.complete(id)
54
62
  rescue => error
55
63
  @processing_queue.retry(id)
56
64
  raise
57
65
  end
58
66
  end
59
-
60
- def each(&block)
61
- while true
62
- process(&block)
63
- end
64
- end
65
67
  end
66
68
  end
67
69
  end
@@ -10,13 +10,9 @@ module Async
10
10
  module Job
11
11
  module Backend
12
12
  module Redis
13
- def self.new(**options)
14
- endpoint = options.fetch(:endpoint) {Async::Redis.local_endpoint}
15
- prefix = options.fetch(:prefix) {"async:job"}
16
-
13
+ def self.new(handler, endpoint: Async::Redis.local_endpoint, prefix: "async:job")
17
14
  client = Async::Redis::Client.new(endpoint)
18
-
19
- return Async::Job::Backend::Redis::Server.new(client, prefix)
15
+ return Server.new(handler, client, prefix)
20
16
  end
21
17
  end
22
18
  end
@@ -0,0 +1,21 @@
1
+ require 'async/queue'
2
+
3
+ module Async
4
+ module Job
5
+ class Buffer
6
+ def initialize
7
+ @jobs = Async::Queue.new
8
+ end
9
+
10
+ attr :jobs
11
+
12
+ def call(job)
13
+ @jobs.enqueue(job)
14
+ end
15
+
16
+ def pop
17
+ @jobs.dequeue
18
+ end
19
+ end
20
+ end
21
+ end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Async
7
7
  module Job
8
- VERSION = "0.2.1"
8
+ VERSION = "0.3.0"
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.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -37,7 +37,7 @@ cert_chain:
37
37
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
38
38
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
39
39
  -----END CERTIFICATE-----
40
- date: 2024-02-24 00:00:00.000000000 Z
40
+ date: 2024-02-25 00:00:00.000000000 Z
41
41
  dependencies:
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: async
@@ -75,12 +75,15 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - lib/async/job.rb
77
77
  - lib/async/job/backend.rb
78
+ - lib/async/job/backend/inline.rb
79
+ - lib/async/job/backend/inline/server.rb
78
80
  - lib/async/job/backend/redis.rb
79
81
  - lib/async/job/backend/redis/delayed_queue.rb
80
82
  - lib/async/job/backend/redis/job_store.rb
81
83
  - lib/async/job/backend/redis/processing_queue.rb
82
84
  - lib/async/job/backend/redis/ready_queue.rb
83
85
  - lib/async/job/backend/redis/server.rb
86
+ - lib/async/job/buffer.rb
84
87
  - lib/async/job/generic.rb
85
88
  - lib/async/job/version.rb
86
89
  - license.md
metadata.gz.sig CHANGED
Binary file