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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +1 -3
- data/lib/octokiq/processor.rb +5 -6
- data/lib/octokiq/server.rb +35 -7
- data/lib/octokiq/version.rb +1 -1
- data/lib/octokiq/worker.rb +18 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8759493bef58bcafe233d6af07ecb747e11aa9f12c285f60082cf3307ce5db6b
|
4
|
+
data.tar.gz: bbbe753f9257e51ea311b3da039b5bfd0573a9a3a1d94353b5550717d5971578
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e135d55a8e6dde10b680241f27a98979d8d61d928d45c3f2c6747fee57d1af4f9bab53ae313f85999669a03974fb557a219dc21cffba24e8aab3343eb68fb28a
|
7
|
+
data.tar.gz: b8f8c68a12044e897a0d8bf6218bd56068c458371c92de891635dd7465cccc95b41127e3ab0b56bd2d6fcf08e3c1ddd927cc1fbfedce38aa9a800f6bdccaf0ac
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/lib/octokiq/processor.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
module Octokiq
|
2
2
|
class Processor
|
3
|
-
attr_accessor :
|
3
|
+
attr_accessor :klass, :args
|
4
4
|
def initialize(job)
|
5
|
-
|
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
|
-
|
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
|
data/lib/octokiq/server.rb
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
module Octokiq
|
2
2
|
class Server
|
3
3
|
def start
|
4
|
-
|
5
|
-
|
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
|
data/lib/octokiq/version.rb
CHANGED
data/lib/octokiq/worker.rb
CHANGED
@@ -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
|
17
|
-
|
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(
|
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.
|
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-
|
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.
|
79
|
+
rubygems_version: 3.2.3
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: Next generation background processing for ruby
|