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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c2780c72c0818659e65f0cf005dcd19d78cb3cb
4
- data.tar.gz: 48fc9366fb03e2efc32df1d865e9358a920db6ff
3
+ metadata.gz: b924bc9aa5b90d80b12a87648a79556806e05afb
4
+ data.tar.gz: f819bc9b7d685856fd493f962c13d0cdbd8ee841
5
5
  SHA512:
6
- metadata.gz: 51fc1856fd6ced06b6f54c483cd6235dd9d095cb9de3359c278f1776ec0c0d7dd106b2fa1acd8c0a9ee095b941dfb35fdb5675459a2122823265a3d6e3420139
7
- data.tar.gz: d8b4bc498f2db51975cde120f6e8ae5815fce0365c86bad579dbb6ccf342d4f30ad8760fc431649cafb59f71b606db7c827530c7d0f284db1d39768bc64e4c6e
6
+ metadata.gz: 02779081ac90c7e27bdf1838e16546beb3381e9756f885361239b0bf03c73d4371fd8bc12f59ba73848bead48ee5a4a3884aa70a608e67ed1174eee5124d08ea
7
+ data.tar.gz: 4b618dfc9164a2de53d1a6ef65de9566644d94ea9e36e8947c2735ca044e910c48a7301c32f66d69346dec285adb8e590fd96ad75642309943316da558bac5d5
@@ -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)
@@ -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
@@ -47,7 +47,7 @@ module Shinq
47
47
  end
48
48
 
49
49
  stats.merge(
50
- queue_count: stats[:rows_removed] - stats[:rows_written]
50
+ queue_count: stats[:rows_written] - stats[:rows_removed]
51
51
  )
52
52
  end
53
53
 
@@ -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
@@ -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
- #TODO use logger
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
@@ -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
@@ -9,6 +9,7 @@ module Shinq
9
9
  def self.rails_bootstrap
10
10
  Shinq.configuration.db_config = ActiveRecord::Base.configurations
11
11
  Shinq.configuration.default_db = ::Rails.env
12
+ Shinq.logger = ::Rails.logger if Shinq.configuration.daemonize
12
13
  end
13
14
  end
14
15
  end
@@ -5,7 +5,7 @@ module Shinq
5
5
  module Statistics
6
6
  def run
7
7
  until @stop
8
- p Shinq::Client.queue_stats(table_name: Shinq.configuration.worker_name.pluralize)
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
@@ -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.3.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.}
@@ -14,6 +14,7 @@ describe Shinq::Configuration do
14
14
  it { is_expected.to respond_to(:queue_timeout) }
15
15
  it { is_expected.to respond_to(:daemonize) }
16
16
  it { is_expected.to respond_to(:statistics) }
17
+ it { is_expected.to respond_to(:lifecycle) }
17
18
  end
18
19
 
19
20
  describe ".new" do
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.3.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-13 00:00:00.000000000 Z
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