octokiq 0.1.2 → 0.1.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 +5 -1
- data/Gemfile.lock +1 -1
- data/exe/octokiq +1 -0
- data/lib/octokiq.rb +5 -17
- data/lib/octokiq/client.rb +31 -0
- data/lib/octokiq/cmd.rb +2 -23
- data/lib/octokiq/configuration.rb +2 -10
- data/lib/octokiq/connection.rb +3 -0
- data/lib/octokiq/consts.rb +8 -0
- data/lib/octokiq/logger.rb +2 -0
- data/lib/octokiq/processor.rb +2 -2
- data/lib/octokiq/server.rb +58 -28
- data/lib/octokiq/version.rb +1 -1
- data/lib/octokiq/worker.rb +4 -7
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44d0f352223a198828049c695b9f9eb6794c9e59e61c78437a725d04c9d89817
|
4
|
+
data.tar.gz: 69a40dc857ffc594a7d73ab3e439aed6f2e03d58923ebd76ee3336c759aa7069
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5be9cc5ff099a09634c0af35e1d1764233f25f8d16f353d7e1c078a3c976dfb6cfd330779146c0e8b209f5a7ce2149e0900c7d0dde2ed5e49bb9fa04d482e5e7
|
7
|
+
data.tar.gz: 364d73063e5133ba872ee90454704212c66462ed4907c5a2f87662b68f12cb318a26e1d9d02a84ba79e03feca1fedb2e92478a4a0c48bc29b926087c688a1b95
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/exe/octokiq
CHANGED
data/lib/octokiq.rb
CHANGED
@@ -1,16 +1,12 @@
|
|
1
|
-
require 'redis'
|
2
|
-
|
3
|
-
require 'etc'
|
4
|
-
require 'logger'
|
5
|
-
require 'json'
|
6
|
-
require 'optparse'
|
7
|
-
|
8
1
|
require 'octokiq/version'
|
9
|
-
require 'octokiq/
|
2
|
+
require 'octokiq/logger'
|
10
3
|
require 'octokiq/connection'
|
11
|
-
require 'octokiq/
|
4
|
+
require 'octokiq/consts'
|
5
|
+
require 'octokiq/configuration'
|
12
6
|
require 'octokiq/processor'
|
7
|
+
require 'octokiq/client'
|
13
8
|
require 'octokiq/server'
|
9
|
+
require 'octokiq/worker'
|
14
10
|
require 'octokiq/cmd'
|
15
11
|
|
16
12
|
module Octokiq
|
@@ -25,14 +21,6 @@ module Octokiq
|
|
25
21
|
@configuration ||= Configuration.new
|
26
22
|
end
|
27
23
|
|
28
|
-
def server_connection
|
29
|
-
@server_connection ||= Connection.new
|
30
|
-
end
|
31
|
-
|
32
|
-
def client_connection
|
33
|
-
@client_connection ||= Connection.new
|
34
|
-
end
|
35
|
-
|
36
24
|
def logger
|
37
25
|
Logger.new($stdout)
|
38
26
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Octokiq
|
2
|
+
module Client
|
3
|
+
extend self
|
4
|
+
|
5
|
+
class Configuration
|
6
|
+
attr_accessor :default_queue
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@default_queue = Consts::DEFAULT_QUEUE
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def push(*args)
|
14
|
+
connection.push(*args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def configure
|
18
|
+
yield(configuration)
|
19
|
+
end
|
20
|
+
|
21
|
+
def configuration
|
22
|
+
@configuration ||= Configuration.new
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def connection
|
28
|
+
@connection ||= Connection.new
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/octokiq/cmd.rb
CHANGED
@@ -2,36 +2,15 @@ module Octokiq
|
|
2
2
|
class CMD
|
3
3
|
def run
|
4
4
|
puts logo
|
5
|
-
|
5
|
+
Server.start
|
6
6
|
rescue Interrupt
|
7
7
|
Octokiq.logger.info 'Bye!'
|
8
8
|
end
|
9
9
|
|
10
10
|
private
|
11
11
|
|
12
|
-
def server
|
13
|
-
@server ||= Server.new
|
14
|
-
end
|
15
|
-
|
16
12
|
def logo
|
17
|
-
|
18
|
-
_,gggggg,_
|
19
|
-
,d8P""d8P"Y8b, I8 ,dPYb,
|
20
|
-
,d8' Y8 "8b,dP I8 IP'`Yb
|
21
|
-
d8' `Ybaaad88P' 88888888 I8 8I gg
|
22
|
-
8P `""""Y8 I8 I8 8bgg, ""
|
23
|
-
8b d8 ,gggg, I8 ,ggggg, I8 dP" "8 gg ,gggg,gg
|
24
|
-
Y8, ,8P dP" "Yb I8 dP" "Y8ggg I8d8bggP" 88 dP" "Y8I
|
25
|
-
`Y8, ,8P' i8' ,I8, i8' ,8I I8P' "Yb, 88 i8' ,8I
|
26
|
-
`Y8b,,__,,d8P' ,d8,_ _ ,d88b, ,d8, ,d8' ,d8 `Yb,_,88,_,d8, ,d8b
|
27
|
-
`"Y8888P"' P""Y8888PP 8P""Y8 P"Y8888P" 88P Y88P""Y8P"Y8888P"88d
|
28
|
-
I8P
|
29
|
-
I8'
|
30
|
-
I8
|
31
|
-
I8
|
32
|
-
I8
|
33
|
-
I8
|
34
|
-
EOF
|
13
|
+
"Hello! Welcome to Octokiq!"
|
35
14
|
end
|
36
15
|
end
|
37
16
|
end
|
@@ -1,17 +1,9 @@
|
|
1
1
|
module Octokiq
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :
|
4
|
-
:queue_prefix,
|
5
|
-
:default_queue,
|
6
|
-
:queues,
|
7
|
-
:force_thread_mode
|
3
|
+
attr_accessor :queue_prefix
|
8
4
|
|
9
5
|
def initialize
|
10
|
-
@
|
11
|
-
@queue_prefix = 'octokiq'
|
12
|
-
@default_queue = 'default'
|
13
|
-
@queues = [@default_queue]
|
14
|
-
@force_thread_mode = false
|
6
|
+
@queue_prefix = Consts::QUEUE_PREFIX
|
15
7
|
end
|
16
8
|
end
|
17
9
|
end
|
data/lib/octokiq/connection.rb
CHANGED
data/lib/octokiq/logger.rb
CHANGED
data/lib/octokiq/processor.rb
CHANGED
@@ -2,8 +2,8 @@ module Octokiq
|
|
2
2
|
class Processor
|
3
3
|
attr_accessor :klass, :args
|
4
4
|
def initialize(job)
|
5
|
-
klass_name = job.fetch(
|
6
|
-
@args = job.fetch(
|
5
|
+
klass_name = job.fetch(Consts::ITEM_CLASS_KEY)
|
6
|
+
@args = job.fetch(Consts::ITEM_ARGS_KEY)
|
7
7
|
@klass = Object.const_get(klass_name)
|
8
8
|
end
|
9
9
|
|
data/lib/octokiq/server.rb
CHANGED
@@ -1,46 +1,84 @@
|
|
1
|
+
require 'etc'
|
2
|
+
|
1
3
|
module Octokiq
|
2
|
-
|
4
|
+
module Server
|
5
|
+
extend self
|
6
|
+
|
7
|
+
class Configuration
|
8
|
+
attr_accessor :concurrency,
|
9
|
+
:queues,
|
10
|
+
:thread_mode
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@concurrency = Etc.nprocessors
|
14
|
+
@queues = [Consts::DEFAULT_QUEUE]
|
15
|
+
@thread_mode = false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def configure
|
20
|
+
yield(configuration)
|
21
|
+
end
|
22
|
+
|
23
|
+
def configuration
|
24
|
+
@configuration ||= Configuration.new
|
25
|
+
end
|
26
|
+
|
3
27
|
def start
|
4
|
-
|
5
|
-
handle_tube
|
28
|
+
configuration.thread_mode ? handle_thread_jobs : ractor_workers
|
6
29
|
|
7
30
|
loop do
|
8
|
-
job =
|
9
|
-
|
31
|
+
job = connection.fetch(queues)
|
32
|
+
pipe << job
|
10
33
|
end
|
11
34
|
end
|
12
35
|
|
13
36
|
private
|
14
37
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
tube << job
|
25
|
-
end
|
38
|
+
def connection
|
39
|
+
@connection ||= Connection.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def ractor_workers
|
43
|
+
@ractor_workers ||= (1..concurrency).map do
|
44
|
+
Ractor.new(pipe) do |pipe|
|
45
|
+
while job = pipe.take
|
46
|
+
Ractor.yield Processor.new(job).run
|
26
47
|
end
|
27
48
|
end
|
28
49
|
end
|
29
50
|
end
|
30
51
|
|
31
|
-
def
|
52
|
+
def handle_thread_jobs
|
53
|
+
semaphore = Mutex.new
|
54
|
+
counter = 0
|
32
55
|
Thread.new do
|
33
|
-
|
34
|
-
|
56
|
+
while counter < concurrency && job = pipe.take
|
57
|
+
semaphore.synchronize { counter += 1 }
|
35
58
|
Thread.new do
|
36
59
|
Processor.new(job).run
|
60
|
+
semaphore.synchronize { counter -= 1 }
|
37
61
|
end
|
38
62
|
end
|
39
63
|
end
|
40
64
|
end
|
41
65
|
|
66
|
+
def thread_workers
|
67
|
+
@thread_workers = []
|
68
|
+
Thread.new do
|
69
|
+
while job = pipe.take
|
70
|
+
Processor.new(job).run
|
71
|
+
end
|
72
|
+
end
|
73
|
+
@thread_workers
|
74
|
+
end
|
75
|
+
|
76
|
+
def concurrency
|
77
|
+
@concurrency ||= configuration.concurrency
|
78
|
+
end
|
79
|
+
|
42
80
|
def queues
|
43
|
-
|
81
|
+
configuration.queues
|
44
82
|
end
|
45
83
|
|
46
84
|
def pipe
|
@@ -50,13 +88,5 @@ module Octokiq
|
|
50
88
|
end
|
51
89
|
end
|
52
90
|
end
|
53
|
-
|
54
|
-
def tube
|
55
|
-
@tube ||= Ractor.new do
|
56
|
-
loop do
|
57
|
-
Ractor.yield Ractor.receive
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
91
|
end
|
62
92
|
end
|
data/lib/octokiq/version.rb
CHANGED
data/lib/octokiq/worker.rb
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
module Octokiq
|
2
2
|
module Worker
|
3
|
-
CLASS_KEY = 'class'.freeze
|
4
|
-
ARGS_KEY = 'args'.freeze
|
5
|
-
|
6
3
|
class Configuration
|
7
4
|
OPTIONS = [:queue].freeze
|
8
5
|
attr_accessor(*OPTIONS)
|
9
6
|
|
10
7
|
def initialize
|
11
|
-
@queue =
|
8
|
+
@queue = Client.configuration.default_queue
|
12
9
|
end
|
13
10
|
end
|
14
11
|
|
@@ -18,7 +15,7 @@ module Octokiq
|
|
18
15
|
|
19
16
|
module ClassMethods
|
20
17
|
def perform_async(*args)
|
21
|
-
|
18
|
+
_push(Consts::ITEM_CLASS_KEY => self, Consts::ITEM_ARGS_KEY => args)
|
22
19
|
end
|
23
20
|
|
24
21
|
def configuration
|
@@ -33,8 +30,8 @@ module Octokiq
|
|
33
30
|
|
34
31
|
private
|
35
32
|
|
36
|
-
def
|
37
|
-
|
33
|
+
def _push(item)
|
34
|
+
Client.push(configuration.queue, item)
|
38
35
|
end
|
39
36
|
end
|
40
37
|
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.3
|
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-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -45,9 +45,11 @@ files:
|
|
45
45
|
- bin/setup
|
46
46
|
- exe/octokiq
|
47
47
|
- lib/octokiq.rb
|
48
|
+
- lib/octokiq/client.rb
|
48
49
|
- lib/octokiq/cmd.rb
|
49
50
|
- lib/octokiq/configuration.rb
|
50
51
|
- lib/octokiq/connection.rb
|
52
|
+
- lib/octokiq/consts.rb
|
51
53
|
- lib/octokiq/logger.rb
|
52
54
|
- lib/octokiq/processor.rb
|
53
55
|
- lib/octokiq/server.rb
|