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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c4bdf49bc448e94756a084b9ccd2ada75a5a3b74b48d92a2e598a8eeba47961
4
- data.tar.gz: 743856cc10d998e7f0e1be88eaadcf1d5f2a66759e3819b4dc733439da49178c
3
+ metadata.gz: bc3982eaa19478a86cd8b4c4a798ad53753e6352aef0a1ce8b71eb80f2583f9a
4
+ data.tar.gz: 2588cc9f482cd5b90711d732cc70f4e09b2291a105e44dfeba91ec6ce2e0de30
5
5
  SHA512:
6
- metadata.gz: 88f7d30be4b531ddb717d51db662ffd7cd7473f6da5b48efc13fdd1b05ac95910b5168cbd60ba1aceac74c69b02794e76b27df2ade238ac3b4dbb45fc87e0f49
7
- data.tar.gz: 7648f507ae5e5fc9d05adfb939d3210de6992f5cc99758921ae83ce6b210294147d4a84f9bc4fda733384e10699b68c38f4456f2b863282b5e777d35d51b85b4
6
+ metadata.gz: d2169928b281facd7d75ceff0c471ec9446d8376505acc78087996a51ebd2060669f5059ece4e75ea7f6e2a9423ba872d76d7465de476dd88f9b9ee9615c46a3
7
+ data.tar.gz: f3484b76fd14d868370934bb0bd919ce336fc394df830cb7236f6b3afe3e242be30f256a6598af9c7bef0881bf48562939bfd9267e335a0af2206bf70e5061c0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.3] - 2023-08-14
4
+
5
+ - Make queues and queue priorities optional when initializing a Server instance
6
+
3
7
  ## [0.2.2] - 2023-08-14
4
8
 
5
9
  - Add logging
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- litejob (0.2.2)
4
+ litejob (0.2.3)
5
5
  litequeue (>= 0.2.1)
6
6
  litescheduler (>= 0.2.1)
7
7
 
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-100%25-brightgreen)
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
 
@@ -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 StandardError => e
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 StandardError => e
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('=') }.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.class.name == exception.message
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
@@ -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
- # TODO: make queues use [["default", 1]]
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Litejob
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.3"
5
5
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: litejob
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mohamed Hassan