async-job-processor-redis 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/async/job/processor/redis/delayed_jobs.rb +5 -0
- data/lib/async/job/processor/redis/processing_list.rb +12 -0
- data/lib/async/job/processor/redis/ready_list.rb +5 -0
- data/lib/async/job/processor/redis/server.rb +27 -0
- data/lib/async/job/processor/redis/version.rb +1 -1
- data/readme.md +4 -0
- data/releases.md +4 -0
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dd229182e417f662b414408d5b49a3c789791f63d7178d2d3acd4c30345b097
|
4
|
+
data.tar.gz: 2f28fd28ebbe51ea344810a039aa2985f68bf4b3934240dabb5d5949e9ffa06c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8818c38d052f06d17c8ada64d537ac996c3bb62bfbbb11c6965e7efa55f4c08b25f19ac9d50c44799b0dd3adcc7b8592ab573cf9793e0fab4500a09c3cfe560a
|
7
|
+
data.tar.gz: 9f8a5d182e4f9e7fff41bd01a328a6c50a1349a6dc9136e5fb1566d549e5558e624ccb9442d56e15a32779b5f6b0de4c67b2da619ebc6d8815f58e9183636cc0
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -36,6 +36,11 @@ module Async
|
|
36
36
|
@move = @client.script(:load, MOVE)
|
37
37
|
end
|
38
38
|
|
39
|
+
# @returns [Integer] The number of jobs currently in the delayed queue.
|
40
|
+
def size
|
41
|
+
@client.zcard(@key)
|
42
|
+
end
|
43
|
+
|
39
44
|
# Start the background task that moves ready delayed jobs to the ready queue.
|
40
45
|
# @parameter ready_list [ReadyList] The ready list to move jobs to.
|
41
46
|
# @parameter resolution [Integer] The check interval in seconds.
|
@@ -73,6 +73,8 @@ module Async
|
|
73
73
|
@requeue = @client.script(:load, REQUEUE)
|
74
74
|
@retry = @client.script(:load, RETRY)
|
75
75
|
@complete = @client.script(:load, COMPLETE)
|
76
|
+
|
77
|
+
@complete_count = 0
|
76
78
|
end
|
77
79
|
|
78
80
|
# @attribute [String] The base Redis key for this processing list.
|
@@ -81,6 +83,14 @@ module Async
|
|
81
83
|
# @attribute [String] The Redis key for this worker's heartbeat.
|
82
84
|
attr :heartbeat_key
|
83
85
|
|
86
|
+
# @attribute [Integer] The total count of all jobs completed by this worker.
|
87
|
+
attr :complete_count
|
88
|
+
|
89
|
+
# @returns [Integer] The number of jobs currently being processed by this worker.
|
90
|
+
def size
|
91
|
+
@client.llen(@pending_key)
|
92
|
+
end
|
93
|
+
|
84
94
|
# Fetch the next job from the ready queue, moving it to this worker's pending list.
|
85
95
|
# This is a blocking operation that waits until a job is available.
|
86
96
|
# @returns [String, nil] The job ID, or nil if no job is available.
|
@@ -91,6 +101,8 @@ module Async
|
|
91
101
|
# Mark a job as completed, removing it from the pending list and job store.
|
92
102
|
# @parameter id [String] The job ID to complete.
|
93
103
|
def complete(id)
|
104
|
+
@complete_count += 1
|
105
|
+
|
94
106
|
@client.evalsha(@complete, 2, @pending_key, @job_store.key, id)
|
95
107
|
end
|
96
108
|
|
@@ -28,6 +28,11 @@ module Async
|
|
28
28
|
# @attribute [String] The Redis key for this ready list.
|
29
29
|
attr :key
|
30
30
|
|
31
|
+
# @returns [Integer] The number of jobs currently in the ready list.
|
32
|
+
def size
|
33
|
+
@client.llen(@key)
|
34
|
+
end
|
35
|
+
|
31
36
|
# Add a new job to the ready queue.
|
32
37
|
# @parameter job [String] The serialized job data.
|
33
38
|
# @parameter job_store [JobStore] The job store to save the job data.
|
@@ -85,6 +85,21 @@ module Async
|
|
85
85
|
super
|
86
86
|
end
|
87
87
|
|
88
|
+
# Generates a human-readable string representing the current statistics.
|
89
|
+
#
|
90
|
+
# e.g. `R=3.42K D=1.23K P=7/2.34K``
|
91
|
+
#
|
92
|
+
# This can be interpreted as:
|
93
|
+
#
|
94
|
+
# - R: Number of jobs in the ready list
|
95
|
+
# - D: Number of jobs in the delayed queue
|
96
|
+
# - P: Number of jobs currently being processed / total number of completed jobs.
|
97
|
+
#
|
98
|
+
# @returns [String] A string representing the current statistics.
|
99
|
+
def status_string
|
100
|
+
"R=#{format_count(@ready_list.size)} D=#{format_count(@delayed_jobs.size)} P=#{format_count(@processing_list.size)}/#{format_count(@processing_list.complete_count)}"
|
101
|
+
end
|
102
|
+
|
88
103
|
# Submit a new job for processing.
|
89
104
|
# Jobs with a scheduled_at time are queued for delayed processing, while immediate jobs are added to the ready queue.
|
90
105
|
# @parameter job [Hash] The job data to process.
|
@@ -121,6 +136,18 @@ module Async
|
|
121
136
|
ensure
|
122
137
|
@processing_list.retry(_id) if _id
|
123
138
|
end
|
139
|
+
|
140
|
+
private
|
141
|
+
|
142
|
+
def format_count(value)
|
143
|
+
if value > 1_000_000
|
144
|
+
"#{(value/1_000_000.0).round(2)}M"
|
145
|
+
elsif value > 1_000
|
146
|
+
"#{(value/1_000.0).round(2)}K"
|
147
|
+
else
|
148
|
+
value
|
149
|
+
end
|
150
|
+
end
|
124
151
|
end
|
125
152
|
end
|
126
153
|
end
|
data/readme.md
CHANGED
@@ -16,6 +16,10 @@ Please see the [project documentation](https://socketry.github.io/async-job-proc
|
|
16
16
|
|
17
17
|
Please see the [project releases](https://socketry.github.io/async-job-processor-redis/releases/index) for all releases.
|
18
18
|
|
19
|
+
### v0.3.0
|
20
|
+
|
21
|
+
- Add `Async::Job::Processor::Redis::Server#status_string` method to return a string with the current job counts.
|
22
|
+
|
19
23
|
### v0.2.0
|
20
24
|
|
21
25
|
- Achieve 100% documentation coverage.
|
data/releases.md
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|