octokiq 0.1.0 → 0.1.1

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: 387dcbd87d4bf68d9cef986923fe654c1d62a1a13ed9288f1cc2c4c5edc7647d
4
- data.tar.gz: ad3bf793c30fa11cb61bc59f5bf2479eb884030f3590a2650af671170214deb5
3
+ metadata.gz: 8759493bef58bcafe233d6af07ecb747e11aa9f12c285f60082cf3307ce5db6b
4
+ data.tar.gz: bbbe753f9257e51ea311b3da039b5bfd0573a9a3a1d94353b5550717d5971578
5
5
  SHA512:
6
- metadata.gz: 2b5ffccf25e4d3033c886dddaaaf4446bb62a6e29fe4312b8fa147931c9b0aafcbdd47fe15fdcf1621a03c4eb32c1bc15d070a8f5225d6ce6733f18c00fb4f6d
7
- data.tar.gz: 795233440f34f446b6897615bac42923f5e1a848a10ae9ebcdfd131f626ac0c55f11a50ccf812de8fc8459460a61714f520a90f386488e045d62d6c45fdb9862
6
+ metadata.gz: e135d55a8e6dde10b680241f27a98979d8d61d928d45c3f2c6747fee57d1af4f9bab53ae313f85999669a03974fb557a219dc21cffba24e8aab3343eb68fb28a
7
+ data.tar.gz: b8f8c68a12044e897a0d8bf6218bd56068c458371c92de891635dd7465cccc95b41127e3ab0b56bd2d6fcf08e3c1ddd927cc1fbfedce38aa9a800f6bdccaf0ac
@@ -3,3 +3,8 @@
3
3
  ## 0.1.0 - 2020-12-29
4
4
 
5
5
  Initial release 🚀
6
+
7
+ ## 0.1.1 - 2020-12-30
8
+
9
+ - Replace worker class configuration `queue` with `octokiq_options`
10
+ - Enable non-ractor safe job running with traditional `Thread`
data/README.md CHANGED
@@ -20,9 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- Run worker server:
24
-
25
- $ bundle exec octokiq
23
+ https://github.com/BranLiang/octokiq/tree/main/examples
26
24
 
27
25
  ## Development
28
26
 
@@ -1,15 +1,14 @@
1
1
  module Octokiq
2
2
  class Processor
3
- attr_accessor :job
3
+ attr_accessor :klass, :args
4
4
  def initialize(job)
5
- @job = job
5
+ klass_name = job.fetch(Worker::CLASS_KEY)
6
+ @args = job.fetch(Worker::ARGS_KEY)
7
+ @klass = Object.const_get(klass_name)
6
8
  end
7
9
 
8
10
  def run
9
- Octokiq.logger.info "Job: #{job}"
10
- klass = job.fetch(Worker::CLASS_KEY)
11
- args = job.fetch(Worker::ARGS_KEY)
12
- Object.const_get(klass).new.perform(*args)
11
+ klass.new.perform(*args)
13
12
  end
14
13
  end
15
14
  end
@@ -1,13 +1,8 @@
1
1
  module Octokiq
2
2
  class Server
3
3
  def start
4
- (1..Octokiq.configuration.processors_count).map do
5
- Ractor.new(pipe) do |pipe|
6
- job = pipe.take
7
- processor = Processor.new(job)
8
- processor.run
9
- end
10
- end
4
+ handle_pipe
5
+ handle_tube
11
6
 
12
7
  loop do
13
8
  job = Octokiq.server_connection.fetch(queues)
@@ -17,6 +12,31 @@ module Octokiq
17
12
 
18
13
  private
19
14
 
15
+ def handle_pipe
16
+ (1..Octokiq.configuration.processors_count).map do
17
+ Ractor.new(pipe, tube) do |pipe, tube|
18
+ job = pipe.take
19
+ begin
20
+ Processor.new(job).run
21
+ rescue Ractor::IsolationError => e
22
+ Octokiq.logger.warn 'Ractor::IsolationError'
23
+ tube << job
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ def handle_tube
30
+ Thread.new do
31
+ loop do
32
+ job = tube.take
33
+ Thread.new do
34
+ Processor.new(job).run
35
+ end
36
+ end
37
+ end
38
+ end
39
+
20
40
  def queues
21
41
  Octokiq.configuration.queues
22
42
  end
@@ -28,5 +48,13 @@ module Octokiq
28
48
  end
29
49
  end
30
50
  end
51
+
52
+ def tube
53
+ @tube ||= Ractor.new do
54
+ loop do
55
+ Ractor.yield Ractor.receive
56
+ end
57
+ end
58
+ end
31
59
  end
32
60
  end
@@ -1,3 +1,3 @@
1
1
  module Octokiq
2
- VERSION = "0.1.0"
2
+ VERSION = '0.1.1'.freeze
3
3
  end
@@ -3,9 +3,17 @@ module Octokiq
3
3
  CLASS_KEY = 'class'.freeze
4
4
  ARGS_KEY = 'args'.freeze
5
5
 
6
+ class Configuration
7
+ OPTIONS = [:queue].freeze
8
+ attr_accessor(*OPTIONS)
9
+
10
+ def initialize
11
+ @queue = Octokiq.configuration.default_queue
12
+ end
13
+ end
14
+
6
15
  def self.included(base)
7
16
  base.extend(ClassMethods)
8
- base.queue(Octokiq.configuration.default_queue)
9
17
  end
10
18
 
11
19
  module ClassMethods
@@ -13,14 +21,20 @@ module Octokiq
13
21
  client_push(CLASS_KEY => self, ARGS_KEY => args)
14
22
  end
15
23
 
16
- def queue(name)
17
- @@queue = name
24
+ def configuration
25
+ @configuration ||= Configuration.new
26
+ end
27
+
28
+ def octokiq_options(opts)
29
+ opts.slice(*Configuration::OPTIONS).each do |key, value|
30
+ configuration.instance_variable_set("@#{key}", value)
31
+ end
18
32
  end
19
33
 
20
34
  private
21
35
 
22
36
  def client_push(item)
23
- Octokiq.client_connection.push(@@queue, item)
37
+ Octokiq.client_connection.push(configuration.queue, item)
24
38
  end
25
39
  end
26
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octokiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bran Liang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-29 00:00:00.000000000 Z
11
+ date: 2020-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  requirements: []
79
- rubygems_version: 3.1.4
79
+ rubygems_version: 3.2.3
80
80
  signing_key:
81
81
  specification_version: 4
82
82
  summary: Next generation background processing for ruby