async-job 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/async/job/backend/inline/server.rb +7 -2
- data/lib/async/job/backend/redis/processing_queue.rb +1 -1
- data/lib/async/job/backend/redis/server.rb +15 -7
- data/lib/async/job/coder.rb +2 -2
- data/lib/async/job/version.rb +1 -1
- data/readme.md +4 -0
- data.tar.gz.sig +0 -0
- metadata +7 -8
- metadata.gz.sig +0 -0
- data/lib/async/job/coder/json.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0c2495e88bb7e1dd1636fd03290813e4d9ca0837157d9e6b145cb098e68a616
|
4
|
+
data.tar.gz: 0e050ec503af7ac00c620bf822358a794dfa12c71d829850df2d668d09d9830e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 863fe9d09f5afacaf38e912d31cbaab011b019b7b3737f0fa21f196a4fb0b76f4b3da2169178ce1c20576b26cae8e98469707e2c3fbf01826670aa2638794524
|
7
|
+
data.tar.gz: cfffcc7dc08d90a95109247341a0728e920305a2ebc55b3fe568970a674fe654c7aa7033ff12a6d4c0461ac0baf5057dfc0ee9bfc0816ae9f2e43397cb722195
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -5,24 +5,29 @@
|
|
5
5
|
|
6
6
|
require_relative '../../coder'
|
7
7
|
|
8
|
+
require 'async/idler'
|
9
|
+
|
8
10
|
module Async
|
9
11
|
module Job
|
10
12
|
module Backend
|
11
13
|
module Inline
|
12
14
|
class Server
|
13
|
-
def initialize(delegate)
|
15
|
+
def initialize(delegate, parent: nil)
|
14
16
|
@delegate = delegate
|
17
|
+
@parent = parent || Async::Idler.new
|
15
18
|
end
|
16
19
|
|
17
20
|
def call(job)
|
18
21
|
scheduled_at = Coder::Time(job["scheduled_at"])
|
19
22
|
|
20
|
-
|
23
|
+
@parent.async do
|
21
24
|
if scheduled_at
|
22
25
|
sleep(scheduled_at - Time.now)
|
23
26
|
end
|
24
27
|
|
25
28
|
@delegate.call(job)
|
29
|
+
rescue => error
|
30
|
+
Console.error(self, error)
|
26
31
|
end
|
27
32
|
end
|
28
33
|
end
|
@@ -7,16 +7,17 @@ require_relative 'delayed_queue'
|
|
7
7
|
require_relative 'job_store'
|
8
8
|
require_relative 'processing_queue'
|
9
9
|
require_relative 'ready_queue'
|
10
|
+
require_relative '../../coder'
|
10
11
|
|
11
12
|
require 'securerandom'
|
12
|
-
|
13
|
+
require 'async/idler'
|
13
14
|
|
14
15
|
module Async
|
15
16
|
module Job
|
16
17
|
module Backend
|
17
18
|
module Redis
|
18
19
|
class Server
|
19
|
-
def initialize(delegate, client, prefix: 'async-job', coder: Coder::DEFAULT, resolution: 10)
|
20
|
+
def initialize(delegate, client, prefix: 'async-job', coder: Coder::DEFAULT, resolution: 10, parent: nil)
|
20
21
|
@delegate = delegate
|
21
22
|
|
22
23
|
@id = SecureRandom.uuid
|
@@ -31,6 +32,8 @@ module Async
|
|
31
32
|
@ready_queue = ReadyQueue.new(@client, "#{@prefix}:ready")
|
32
33
|
|
33
34
|
@processing_queue = ProcessingQueue.new(@client, "#{@prefix}:processing", @id, @ready_queue, @job_store)
|
35
|
+
|
36
|
+
@parent = parent || Async::Idler.new
|
34
37
|
end
|
35
38
|
|
36
39
|
def start
|
@@ -42,7 +45,7 @@ module Async
|
|
42
45
|
@processing_queue.start
|
43
46
|
|
44
47
|
while true
|
45
|
-
self.dequeue
|
48
|
+
self.dequeue(@parent)
|
46
49
|
end
|
47
50
|
end
|
48
51
|
|
@@ -58,16 +61,21 @@ module Async
|
|
58
61
|
|
59
62
|
protected
|
60
63
|
|
61
|
-
def dequeue
|
62
|
-
|
63
|
-
|
64
|
+
def dequeue(parent)
|
65
|
+
_id = @processing_queue.fetch
|
66
|
+
|
67
|
+
parent.async do
|
68
|
+
id = _id; _id = nil
|
69
|
+
|
64
70
|
job = @coder.load(@job_store.get(id))
|
65
71
|
@delegate.call(job)
|
66
72
|
@processing_queue.complete(id)
|
67
73
|
rescue => error
|
68
74
|
@processing_queue.retry(id)
|
69
|
-
|
75
|
+
Console.error(self, error)
|
70
76
|
end
|
77
|
+
ensure
|
78
|
+
@processing_queue.retry(_id) if _id
|
71
79
|
end
|
72
80
|
end
|
73
81
|
end
|
data/lib/async/job/coder.rb
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
# Released under the MIT License.
|
4
4
|
# Copyright, 2024, by Samuel Williams.
|
5
5
|
|
6
|
-
|
6
|
+
require 'json'
|
7
7
|
|
8
8
|
module Async
|
9
9
|
module Job
|
10
10
|
module Coder
|
11
|
-
DEFAULT = JSON
|
11
|
+
DEFAULT = JSON
|
12
12
|
|
13
13
|
# Type-cast for time values. See <https://bugs.ruby-lang.org/issues/20298> for background.
|
14
14
|
# @parameter value [Time || Integer || String || nil]
|
data/lib/async/job/version.rb
CHANGED
data/readme.md
CHANGED
@@ -29,3 +29,7 @@ This project uses the [Developer Certificate of Origin](https://developercertifi
|
|
29
29
|
### Contributor Covenant
|
30
30
|
|
31
31
|
This project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
|
32
|
+
|
33
|
+
## See Also
|
34
|
+
|
35
|
+
- [async-job-adapter-active_job](https://github.com/socketry/async-job-adapter-active_job) - ActiveJob adapter for `async-job`.
|
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -37,22 +37,22 @@ cert_chain:
|
|
37
37
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
38
38
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
39
39
|
-----END CERTIFICATE-----
|
40
|
-
date: 2024-
|
40
|
+
date: 2024-03-06 00:00:00.000000000 Z
|
41
41
|
dependencies:
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: async
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - "
|
46
|
+
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
48
|
+
version: '2.9'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- - "
|
53
|
+
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
55
|
+
version: '2.9'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: async-redis
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,7 +86,6 @@ files:
|
|
86
86
|
- lib/async/job/buffer.rb
|
87
87
|
- lib/async/job/builder.rb
|
88
88
|
- lib/async/job/coder.rb
|
89
|
-
- lib/async/job/coder/json.rb
|
90
89
|
- lib/async/job/coder/marshal.rb
|
91
90
|
- lib/async/job/coder/message_pack.rb
|
92
91
|
- lib/async/job/generic.rb
|
@@ -106,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
105
|
requirements:
|
107
106
|
- - ">="
|
108
107
|
- !ruby/object:Gem::Version
|
109
|
-
version: '3.
|
108
|
+
version: '3.1'
|
110
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
110
|
requirements:
|
112
111
|
- - ">="
|
metadata.gz.sig
CHANGED
Binary file
|
data/lib/async/job/coder/json.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Released under the MIT License.
|
4
|
-
# Copyright, 2024, by Samuel Williams.
|
5
|
-
|
6
|
-
require 'json'
|
7
|
-
|
8
|
-
module Async
|
9
|
-
module Job
|
10
|
-
module Coder
|
11
|
-
class JSON
|
12
|
-
def initialize
|
13
|
-
end
|
14
|
-
|
15
|
-
def dump(job)
|
16
|
-
::JSON.dump(job)
|
17
|
-
end
|
18
|
-
|
19
|
-
def load(data)
|
20
|
-
::JSON.parse(data, symbolize_names: true)
|
21
|
-
end
|
22
|
-
|
23
|
-
DEFAULT = self.new
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|