jobi 0.1.1 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40d1fc4cc7f08510bb497261a241ad8d8978585926b398c74f7b94d7a574a9df
4
- data.tar.gz: 79021f27feb63bc53f9255bde60aa0337d8813b559da8f6e842447dba92c35ae
3
+ metadata.gz: f5481a71ff0b19ad7066d7c291a3a49b54b18c9fd53cfb4fb00192956e88cb01
4
+ data.tar.gz: 9816dc966495967fc5c8b10ac3737090707331cac413dc4b7662f67d8b05d00a
5
5
  SHA512:
6
- metadata.gz: 7f2c2c2ff54b42eba6c571f2b37ee27d6aaa3c8840e71a3d7229218cd5bbe9a07e0f95765a1aa13267bc7fab8e5a48323f5e7f0ad25c0363361e434cd72d9972
7
- data.tar.gz: a901943b861161481019a0e5b392c02ffb12f83adeaf47ab5d74544f7bbff0de5e04a0b0aa2a0ac9fb0b7223f4888018c1c2681b7d2d23169cd3c8248e9bda02
6
+ metadata.gz: 769a03b613847312789ccbd65d95f628155808524b2a0493a8ce186bb3b734e9270b15d0f72f4961274d8df549b2888f384338478a5fb168c853432cf88b074d
7
+ data.tar.gz: 850e662d6c6560b63e08be9834b3296b4b9ec5da7e785e8c23a54bd98ba6a9949f4b1d4d32830cef5d8dda4053c0b8858d089523a55c84e8ee5fc5240ad666ec
@@ -1,8 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.2.1] - 2020-08-22
4
+ ### Added
5
+ - Queue durability.
6
+ - Message persistence.
7
+ ### Updated
8
+ - Gem dependency.
3
9
  ## [0.1.1] - 2020-08-04
4
10
  ### Updated
5
- - Jobi gemspec file.
11
+ - Gemspec file.
12
+ - Readme file.
6
13
  ## [0.1.0] - 2020-08-02
7
14
  ### Added
8
15
  - Initial Jobi structure.
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jobi (0.1.0)
4
+ jobi (0.2.1)
5
5
  bunny (>= 2.14.1)
6
6
  logger
7
+ rake (~> 12.0)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
@@ -42,4 +43,4 @@ DEPENDENCIES
42
43
  rspec (~> 3.0)
43
44
 
44
45
  BUNDLED WITH
45
- 2.1.2
46
+ 2.1.4
data/README.md CHANGED
@@ -74,17 +74,21 @@ class ExampleJob < Jobi::Job
74
74
  # Queue name that will be used for publishing and consuming messages.
75
75
  # Force acknowledge of the message or not.
76
76
  # Number of consumers that will consume from this queue.
77
+ # Queue durability to survive broker restart, by default it is true.
78
+ # Message persistence to survive broker restart.
77
79
  options queue_name: :example,
78
80
  ack: true,
79
- consumers: 5
81
+ consumers: 5,
82
+ durable: true,
83
+ persist: true
80
84
 
81
85
  # Will be called after run.
82
86
  after_run :print_sum
83
87
 
84
88
  # Entry point of the job
85
89
  def initialize(arg1:, arg2:)
86
- @arg1 = @arg1
87
- @arg2 = @arg2
90
+ @arg1 = arg1
91
+ @arg2 = arg2
88
92
  end
89
93
 
90
94
  def run
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- jobi (0.1.0)
4
+ jobi (0.1.1)
5
5
  bunny (>= 2.14.1)
6
6
  logger
7
+ rspec (~> 3.0)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
@@ -84,6 +85,7 @@ GEM
84
85
  childprocess (3.0.0)
85
86
  concurrent-ruby (1.1.6)
86
87
  crass (1.0.6)
88
+ diff-lcs (1.4.4)
87
89
  erubi (1.9.0)
88
90
  ffi (1.13.1)
89
91
  globalid (0.4.2)
@@ -151,6 +153,19 @@ GEM
151
153
  rb-inotify (0.10.1)
152
154
  ffi (~> 1.0)
153
155
  regexp_parser (1.7.1)
156
+ rspec (3.9.0)
157
+ rspec-core (~> 3.9.0)
158
+ rspec-expectations (~> 3.9.0)
159
+ rspec-mocks (~> 3.9.0)
160
+ rspec-core (3.9.2)
161
+ rspec-support (~> 3.9.3)
162
+ rspec-expectations (3.9.2)
163
+ diff-lcs (>= 1.2.0, < 2.0)
164
+ rspec-support (~> 3.9.0)
165
+ rspec-mocks (3.9.1)
166
+ diff-lcs (>= 1.2.0, < 2.0)
167
+ rspec-support (~> 3.9.0)
168
+ rspec-support (3.9.3)
154
169
  ruby_dep (1.5.0)
155
170
  rubyzip (2.3.0)
156
171
  sass (3.7.4)
@@ -234,4 +249,4 @@ RUBY VERSION
234
249
  ruby 2.7.0p0
235
250
 
236
251
  BUNDLED WITH
237
- 2.1.2
252
+ 2.1.4
@@ -1,7 +1,9 @@
1
1
  class CalculatorJob < ApplicationJob
2
2
  options queue_name: :calculator,
3
3
  ack: true,
4
- consumers: 5
4
+ consumers: 5,
5
+ durable: true,
6
+ persist: true
5
7
 
6
8
  def initialize(number1:, number2:)
7
9
  @number1 = number1
@@ -5,7 +5,9 @@ require 'jobi'
5
5
  class NormalJob < Jobi::Job
6
6
  options queue_name: :calculators,
7
7
  ack: true,
8
- consumers: 10
8
+ consumers: 10,
9
+ durable: true,
10
+ persist: true
9
11
 
10
12
  after_run :publish_result
11
13
 
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ["lib"]
27
27
 
28
- spec.add_dependency 'bunny', ">= 2.14.1"
28
+ spec.add_dependency 'bunny', '>= 2.14.1'
29
29
  spec.add_dependency 'logger'
30
- spec.add_dependency 'rspec', "~> 3.0"
30
+ spec.add_dependency 'rake', '~> 12.0'
31
31
  end
@@ -3,6 +3,15 @@ require 'bunny'
3
3
  module Jobi
4
4
  module Clients
5
5
  class Rabbitmq
6
+
7
+ QUEUE_OPTIONS = {
8
+ durable: :durable
9
+ }.freeze
10
+
11
+ MESSAGE_OPTIONS = {
12
+ persist: :persistent
13
+ }.freeze
14
+
6
15
  def initialize(config = Jobi::Config::Rabbitmq.new)
7
16
  @connection = Bunny.new(config.to_h)
8
17
  @connection.start
@@ -18,11 +27,20 @@ module Jobi
18
27
 
19
28
  def queue(name:, options: {})
20
29
  default_exchange
21
- channel.queue(name)
30
+ channel.queue(name, build_options(options, QUEUE_OPTIONS))
22
31
  end
23
32
 
24
33
  def publish(message:, queue:, options: {})
25
- queue.publish(message)
34
+ queue.publish(message, build_options(options, MESSAGE_OPTIONS))
35
+ end
36
+
37
+ private
38
+
39
+ def build_options(options = {}, original_options)
40
+ options.inject({}) do |mapped_options, (key, value)|
41
+ mapped_options[original_options[key]] = value
42
+ mapped_options
43
+ end
26
44
  end
27
45
  end
28
46
  end
@@ -6,10 +6,12 @@ module Jobi
6
6
  class << self
7
7
  include Utils
8
8
 
9
- def options(queue_name:, ack: false, consumers: 5)
9
+ def options(queue_name:, ack: false, consumers: 5, durable: true, persist: false)
10
10
  @queue_name = queue_name.to_s
11
11
  @ack = ack
12
12
  @consumers = consumers
13
+ @durable = durable
14
+ @persist = persist
13
15
  end
14
16
 
15
17
  def after_run(callback)
@@ -30,7 +32,6 @@ module Jobi
30
32
  return unless Jobi.consumer?
31
33
 
32
34
  join_queue
33
-
34
35
  @consumer_threads = []
35
36
  @consumers.times do
36
37
  @consumer_threads << Thread.new { consumer.consume! }
@@ -59,15 +60,12 @@ module Jobi
59
60
 
60
61
  def join_queue
61
62
  @queue = Jobi.session
62
- .queue(name: @queue_name)
63
+ .queue(**build_queue_params)
63
64
  end
64
65
 
65
66
  def publish_message
66
67
  Jobi.session
67
- .publish(
68
- message: Marshal.dump(@message),
69
- queue: @queue
70
- )
68
+ .publish(**build_message_params)
71
69
  end
72
70
 
73
71
  def create_message(args:)
@@ -84,6 +82,25 @@ module Jobi
84
82
  Jobi.logger.debug("Args: #{@message.args}")
85
83
  Jobi.logger.debug("Job class: '#{@message.job_class}'")
86
84
  end
85
+
86
+ def build_queue_params
87
+ {
88
+ name: @queue_name,
89
+ options: {
90
+ durable: @durable
91
+ }
92
+ }
93
+ end
94
+
95
+ def build_message_params
96
+ {
97
+ message: Marshal.dump(@message),
98
+ queue: @queue,
99
+ options: {
100
+ persist: @persist
101
+ }
102
+ }
103
+ end
87
104
  end
88
105
  end
89
106
  end
@@ -1,3 +1,3 @@
1
1
  module Jobi
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jobi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rudy Zidan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-04 00:00:00.000000000 Z
11
+ date: 2020-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -39,19 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '12.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '12.0'
55
55
  description: Jobi provides a full interaction between your app/micro-service and message
56
56
  brokers.
57
57
  email:
@@ -73,7 +73,6 @@ files:
73
73
  - README.md
74
74
  - Rakefile
75
75
  - bin/console
76
- - bin/jobi.log
77
76
  - bin/setup
78
77
  - examples/demo_app/.browserslistrc
79
78
  - examples/demo_app/.gitignore
@@ -1,31 +0,0 @@
1
- # Logfile created on 2020-08-02 14:14:00 +0300 by logger.rb/v1.4.2
2
- I, [2020-08-02T14:15:03.498961 #20403] INFO -- : Completed in: 0.0006229877471923828
3
- I, [2020-08-02T14:15:03.499179 #20403] INFO -- : Completed in: 0.0006537437438964844
4
- I, [2020-08-02T14:15:03.499314 #20403] INFO -- : Completed in: 0.0006098747253417969
5
- I, [2020-08-02T14:15:03.499436 #20403] INFO -- : Completed in: 0.0005278587341308594
6
- I, [2020-08-02T14:15:03.499611 #20403] INFO -- : Completed in: 0.0005152225494384766
7
- I, [2020-08-02T14:15:03.500180 #20403] INFO -- : Completed in: 0.0008637905120849609
8
- I, [2020-08-02T14:15:03.500406 #20403] INFO -- : Completed in: 0.00044274330139160156
9
- I, [2020-08-02T14:15:03.500572 #20403] INFO -- : Completed in: 0.00039005279541015625
10
- I, [2020-08-02T14:15:03.500787 #20403] INFO -- : Completed in: 0.0004138946533203125
11
- I, [2020-08-02T14:15:03.500969 #20403] INFO -- : Completed in: 0.00039124488830566406
12
- I, [2020-08-02T14:15:15.597311 #20403] INFO -- : Completed in: 0.00615382194519043
13
- I, [2020-08-02T14:15:15.597544 #20403] INFO -- : Completed in: 0.0005860328674316406
14
- I, [2020-08-02T14:15:15.597729 #20403] INFO -- : Completed in: 0.0006017684936523438
15
- I, [2020-08-02T14:15:15.597903 #20403] INFO -- : Completed in: 0.0005707740783691406
16
- I, [2020-08-02T14:15:15.598084 #20403] INFO -- : Completed in: 0.0005507469177246094
17
- I, [2020-08-02T14:15:15.598269 #20403] INFO -- : Completed in: 0.0005309581756591797
18
- I, [2020-08-02T14:15:15.598435 #20403] INFO -- : Completed in: 0.00045490264892578125
19
- I, [2020-08-02T14:15:15.598588 #20403] INFO -- : Completed in: 0.0004150867462158203
20
- I, [2020-08-02T14:15:15.598801 #20403] INFO -- : Completed in: 0.0004291534423828125
21
- I, [2020-08-02T14:15:15.599029 #20403] INFO -- : Completed in: 0.00044798851013183594
22
- I, [2020-08-02T14:15:23.420378 #20403] INFO -- : Completed in: 0.006279945373535156
23
- I, [2020-08-02T14:15:23.420583 #20403] INFO -- : Completed in: 0.0005891323089599609
24
- I, [2020-08-02T14:15:23.420811 #20403] INFO -- : Completed in: 0.0005612373352050781
25
- I, [2020-08-02T14:15:23.420987 #20403] INFO -- : Completed in: 0.0005502700805664062
26
- I, [2020-08-02T14:15:23.421150 #20403] INFO -- : Completed in: 0.0004863739013671875
27
- I, [2020-08-02T14:15:23.421325 #20403] INFO -- : Completed in: 0.0004470348358154297
28
- I, [2020-08-02T14:15:23.421516 #20403] INFO -- : Completed in: 0.00040793418884277344
29
- I, [2020-08-02T14:15:23.421733 #20403] INFO -- : Completed in: 0.00045680999755859375
30
- I, [2020-08-02T14:15:23.421959 #20403] INFO -- : Completed in: 0.00048613548278808594
31
- I, [2020-08-02T14:15:23.422115 #20403] INFO -- : Completed in: 0.00044798851013183594