shinq 0.3.0 → 0.4.0
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 +4 -4
- data/lib/shinq.rb +8 -0
- data/lib/shinq/cli.rb +8 -1
- data/lib/shinq/client.rb +1 -1
- data/lib/shinq/configuration.rb +2 -2
- data/lib/shinq/launcher.rb +15 -2
- data/lib/shinq/logger.rb +17 -0
- data/lib/shinq/rails.rb +1 -0
- data/lib/shinq/statistics.rb +1 -1
- data/shinq.gemspec +1 -1
- data/spec/shinq/configuration_spec.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b924bc9aa5b90d80b12a87648a79556806e05afb
|
4
|
+
data.tar.gz: f819bc9b7d685856fd493f962c13d0cdbd8ee841
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02779081ac90c7e27bdf1838e16546beb3381e9756f885361239b0bf03c73d4371fd8bc12f59ba73848bead48ee5a4a3884aa70a608e67ed1174eee5124d08ea
|
7
|
+
data.tar.gz: 4b618dfc9164a2de53d1a6ef65de9566644d94ea9e36e8947c2735ca044e910c48a7301c32f66d69346dec285adb8e590fd96ad75642309943316da558bac5d5
|
data/lib/shinq.rb
CHANGED
@@ -31,6 +31,14 @@ module Shinq
|
|
31
31
|
@connections ||= {}
|
32
32
|
@connections[db_name] ||= setup_db_connection(db_name)
|
33
33
|
end
|
34
|
+
|
35
|
+
def self.logger
|
36
|
+
@logger
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.logger=(log)
|
40
|
+
@logger = log
|
41
|
+
end
|
34
42
|
end
|
35
43
|
|
36
44
|
require 'shinq/rails' if defined?(::Rails::Engine)
|
data/lib/shinq/cli.rb
CHANGED
@@ -4,6 +4,7 @@ require 'shinq'
|
|
4
4
|
require 'shinq/launcher'
|
5
5
|
require 'shinq/statistics'
|
6
6
|
require 'shinq/configuration'
|
7
|
+
require 'shinq/logger'
|
7
8
|
require 'serverengine'
|
8
9
|
|
9
10
|
module Shinq
|
@@ -54,6 +55,10 @@ module Shinq
|
|
54
55
|
opts[:require] = v
|
55
56
|
end
|
56
57
|
|
58
|
+
opt.on('-l', '--max-lifecycle VALUE', 'Refork process when loopnumber is over specify number') do |v|
|
59
|
+
opts[:lifecycle] = v.to_i
|
60
|
+
end
|
61
|
+
|
57
62
|
opt.on('-s', '--statistics VALUE', 'Display queue statistics interval time(sec)') do |v|
|
58
63
|
opts[:statistics] = v.to_i
|
59
64
|
end
|
@@ -74,6 +79,7 @@ module Shinq
|
|
74
79
|
|
75
80
|
def bootstrap
|
76
81
|
target = options.require
|
82
|
+
Shinq.logger = Shinq::Logger.logger
|
77
83
|
|
78
84
|
if File.directory?(target)
|
79
85
|
require 'rails'
|
@@ -93,7 +99,8 @@ module Shinq
|
|
93
99
|
daemonize: options.daemonize,
|
94
100
|
worker_type: 'process',
|
95
101
|
pid_file: 'shinq.pid',
|
96
|
-
workers: options.process
|
102
|
+
workers: options.process,
|
103
|
+
logger: options.daemonize ? Shinq.logger : nil
|
97
104
|
})
|
98
105
|
|
99
106
|
se.run
|
data/lib/shinq/client.rb
CHANGED
data/lib/shinq/configuration.rb
CHANGED
@@ -2,7 +2,7 @@ module Shinq
|
|
2
2
|
class ConfigurationError < StandardError; end
|
3
3
|
|
4
4
|
class Configuration
|
5
|
-
attr_accessor :require, :worker_name, :db_config, :queue_db, :default_db, :process, :queue_timeout, :daemonize, :statistics
|
5
|
+
attr_accessor :require, :worker_name, :db_config, :queue_db, :default_db, :process, :queue_timeout, :daemonize, :statistics, :lifecycle
|
6
6
|
|
7
7
|
DEFAULT = {
|
8
8
|
require: '.',
|
@@ -12,7 +12,7 @@ module Shinq
|
|
12
12
|
}
|
13
13
|
|
14
14
|
def initialize(opts)
|
15
|
-
%i(require worker_name db_config queue_db default_db process queue_timeout daemonize statistics).each do |k|
|
15
|
+
%i(require worker_name db_config queue_db default_db process queue_timeout daemonize statistics lifecycle).each do |k|
|
16
16
|
send(:"#{k}=", opts[k] || DEFAULT[k])
|
17
17
|
end
|
18
18
|
end
|
data/lib/shinq/launcher.rb
CHANGED
@@ -7,10 +7,11 @@ module Shinq
|
|
7
7
|
worker_name = Shinq.configuration.worker_name
|
8
8
|
worker_class = worker_name.camelize.constantize
|
9
9
|
|
10
|
+
@loop_count = 0
|
11
|
+
|
10
12
|
until @stop
|
11
13
|
queue = Shinq::Client.dequeue(table_name: worker_name.pluralize)
|
12
|
-
#
|
13
|
-
next p "Queue is empty (#{Time.now})" unless queue
|
14
|
+
next Shinq.logger.info("Queue is empty (#{Time.now})") unless queue
|
14
15
|
|
15
16
|
begin
|
16
17
|
worker_class.new.perform(queue)
|
@@ -20,11 +21,23 @@ module Shinq
|
|
20
21
|
end
|
21
22
|
|
22
23
|
Shinq::Client.done
|
24
|
+
|
25
|
+
@loop_count += 1
|
26
|
+
|
27
|
+
if lifecycle_limit?
|
28
|
+
Shinq.logger.info("Lifecycle Limit pid(#{Process.pid})")
|
29
|
+
break
|
30
|
+
end
|
23
31
|
end
|
24
32
|
end
|
25
33
|
|
26
34
|
def stop
|
27
35
|
@stop = true
|
28
36
|
end
|
37
|
+
|
38
|
+
def lifecycle_limit?
|
39
|
+
return false unless Shinq.configuration.lifecycle
|
40
|
+
return (Shinq.configuration.lifecycle < @loop_count)
|
41
|
+
end
|
29
42
|
end
|
30
43
|
end
|
data/lib/shinq/logger.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Shinq
|
4
|
+
class Logger
|
5
|
+
def self.initialize_logger
|
6
|
+
@logger = ::Logger.new(STDOUT)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.logger=(log)
|
10
|
+
@logger = log
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.logger
|
14
|
+
@logger ? @logger : initialize_logger
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/shinq/rails.rb
CHANGED
data/lib/shinq/statistics.rb
CHANGED
@@ -5,7 +5,7 @@ module Shinq
|
|
5
5
|
module Statistics
|
6
6
|
def run
|
7
7
|
until @stop
|
8
|
-
|
8
|
+
Shinq.logger.info Shinq::Client.queue_stats(table_name: Shinq.configuration.worker_name.pluralize)
|
9
9
|
sleep Shinq.configuration.statistics
|
10
10
|
end
|
11
11
|
end
|
data/shinq.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "shinq"
|
7
|
-
spec.version = '0.
|
7
|
+
spec.version = '0.4.0'
|
8
8
|
spec.authors = ["Ryoichi SEKIGUCHI"]
|
9
9
|
spec.email = ["ryopeko@gmail.com"]
|
10
10
|
spec.summary = %q{Worker and enqueuer for Q4M using the interface of ActiveJob.}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shinq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryoichi SEKIGUCHI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -189,6 +189,7 @@ files:
|
|
189
189
|
- lib/shinq/client.rb
|
190
190
|
- lib/shinq/configuration.rb
|
191
191
|
- lib/shinq/launcher.rb
|
192
|
+
- lib/shinq/logger.rb
|
192
193
|
- lib/shinq/rails.rb
|
193
194
|
- lib/shinq/statistics.rb
|
194
195
|
- shinq.gemspec
|