litejob 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/litejob/processor.rb +11 -11
- data/lib/litejob/server.rb +2 -5
- data/lib/litejob/version.rb +1 -1
- data/lib/litejob.rb +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc3982eaa19478a86cd8b4c4a798ad53753e6352aef0a1ce8b71eb80f2583f9a
|
4
|
+
data.tar.gz: 2588cc9f482cd5b90711d732cc70f4e09b2291a105e44dfeba91ec6ce2e0de30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2169928b281facd7d75ceff0c471ec9446d8376505acc78087996a51ebd2060669f5059ece4e75ea7f6e2a9423ba872d76d7465de476dd88f9b9ee9615c46a3
|
7
|
+
data.tar.gz: f3484b76fd14d868370934bb0bd919ce336fc394df830cb7236f6b3afe3e242be30f256a6598af9c7bef0881bf48562939bfd9267e335a0af2206bf70e5061c0
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/litejob.svg)](https://rubygems.org/gems/litejob)
|
4
4
|
[![Gem Downloads](https://img.shields.io/gem/dt/litejob)](https://rubygems.org/gems/litejob)
|
5
5
|
![Tests](https://github.com/litestack-ruby/litejob/actions/workflows/main.yml/badge.svg)
|
6
|
-
![Coverage](https://img.shields.io/badge/code_coverage-
|
6
|
+
![Coverage](https://img.shields.io/badge/code_coverage-70%25-red)
|
7
7
|
|
8
8
|
Litejob is a Ruby module that enables seamless integration of the Litequeue job queueing system into Ruby applications. By including the Litejob module in a class and implementing the `#perform` method, developers can easily enqueue and process jobs asynchronously.
|
9
9
|
|
data/lib/litejob/processor.rb
CHANGED
@@ -12,7 +12,7 @@ module Litejob
|
|
12
12
|
@serialized_job = serialized_job
|
13
13
|
@job_hash = JSON.parse(@serialized_job)
|
14
14
|
@litequeue = Litequeue.instance
|
15
|
-
|
15
|
+
|
16
16
|
set_log_context!(queue: @queue, class: @job_hash["class"], job: @id)
|
17
17
|
end
|
18
18
|
|
@@ -28,7 +28,7 @@ module Litejob
|
|
28
28
|
begin
|
29
29
|
instance.perform(*@job_hash["params"])
|
30
30
|
log(:end)
|
31
|
-
rescue
|
31
|
+
rescue => e
|
32
32
|
if @job_hash["retries_left"] == 0
|
33
33
|
err(e, "retries exhausted, moving to _dead queue")
|
34
34
|
repush(@id, @job_hash, 0, "_dead")
|
@@ -40,32 +40,32 @@ module Litejob
|
|
40
40
|
repush(@id, @job_hash, retry_delay, @job_hash["queue"])
|
41
41
|
end
|
42
42
|
end
|
43
|
-
rescue
|
43
|
+
rescue => e
|
44
44
|
# this is an error in the extraction of job info, retrying here will not be useful
|
45
45
|
err(e, "while processing job=#{@serialized_job}")
|
46
46
|
raise e
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
private
|
50
|
-
|
50
|
+
|
51
51
|
def set_log_context!(**attributes)
|
52
|
-
@log_context = attributes.map { |k, v| [k, v].join(
|
52
|
+
@log_context = attributes.map { |k, v| [k, v].join("=") }.join(" ")
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def log(event, msg: nil)
|
56
56
|
prefix = "[litejob]:[#{event.to_s.upcase}]"
|
57
|
-
|
57
|
+
|
58
58
|
Litejob.logger.info [prefix, @log_context, msg].compact.join(" ")
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def err(exception, msg = nil)
|
62
62
|
prefix = "[litejob]:[ERR]"
|
63
|
-
error_context = if exception.
|
63
|
+
error_context = if exception.message == exception.class.name
|
64
64
|
"failed with #<#{exception.class.name}>"
|
65
65
|
else
|
66
66
|
"failed with #{exception.inspect}"
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
Litejob.logger.error [prefix, @log_context, error_context, msg].compact.join(" ")
|
70
70
|
end
|
71
71
|
end
|
data/lib/litejob/server.rb
CHANGED
@@ -6,16 +6,14 @@ require_relative "processor"
|
|
6
6
|
|
7
7
|
module Litejob
|
8
8
|
# Litejob::Server is responsible for popping job payloads from the SQLite queue.
|
9
|
-
# :nocov:
|
10
9
|
class Server
|
11
|
-
|
12
|
-
# TODO: make queue priorities optional
|
13
|
-
def initialize(queues)
|
10
|
+
def initialize(queues = ["default"])
|
14
11
|
@queue = Litequeue.instance
|
15
12
|
@scheduler = Litescheduler.instance
|
16
13
|
@queues = queues
|
17
14
|
# group and order queues according to their priority
|
18
15
|
@prioritized_queues = queues.each_with_object({}) do |(name, priority, spawns), memo|
|
16
|
+
priority ||= 5
|
19
17
|
memo[priority] ||= []
|
20
18
|
memo[priority] << [name, spawns == "spawn"]
|
21
19
|
end.sort_by do |priority, _|
|
@@ -68,5 +66,4 @@ module Litejob
|
|
68
66
|
end
|
69
67
|
end
|
70
68
|
end
|
71
|
-
# :nocov:
|
72
69
|
end
|
data/lib/litejob/version.rb
CHANGED
data/lib/litejob.rb
CHANGED
@@ -9,19 +9,19 @@ module Litejob
|
|
9
9
|
def self.included(klass)
|
10
10
|
klass.extend(Concern)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
Configuration = Struct.new(:logger)
|
14
|
-
|
14
|
+
|
15
15
|
def self.configuration
|
16
16
|
@configuration ||= Configuration.new(
|
17
|
-
_logger = Logger.new($stdout)
|
17
|
+
_logger = Logger.new($stdout)
|
18
18
|
)
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def self.configure
|
22
22
|
yield(configuration)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def self.logger
|
26
26
|
configuration.logger
|
27
27
|
end
|