shinq 0.2.0 → 0.3.0

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
  SHA1:
3
- metadata.gz: 27fb65cd784140db7180182ee23747354ea16316
4
- data.tar.gz: d3b16bae80c1e983ddff5a417caa23ae28f1ad0b
3
+ metadata.gz: 1c2780c72c0818659e65f0cf005dcd19d78cb3cb
4
+ data.tar.gz: 48fc9366fb03e2efc32df1d865e9358a920db6ff
5
5
  SHA512:
6
- metadata.gz: d9636a00d1c4d5c9a57fa5a3bdf697bb0814fb3c3caa3f61f4dc775473fb967b0c4f81980609025aaf4d475553bee80d03e6d872f3b428724938aa3f2acc7280
7
- data.tar.gz: 36076bca1dfb6cb3c6d89f18dada6116a22b0b8123ad3e1987980cc030c0d21eec495e0326590ceb6695779d7b32e5c2ece588aa4dc5b5dc98a3bef8fcf82230
6
+ metadata.gz: 51fc1856fd6ced06b6f54c483cd6235dd9d095cb9de3359c278f1776ec0c0d7dd106b2fa1acd8c0a9ee095b941dfb35fdb5675459a2122823265a3d6e3420139
7
+ data.tar.gz: d8b4bc498f2db51975cde120f6e8ae5815fce0365c86bad579dbb6ccf342d4f30ad8760fc431649cafb59f71b606db7c827530c7d0f284db1d39768bc64e4c6e
data/lib/shinq/cli.rb CHANGED
@@ -2,6 +2,7 @@ require 'optparse'
2
2
  require 'yaml'
3
3
  require 'shinq'
4
4
  require 'shinq/launcher'
5
+ require 'shinq/statistics'
5
6
  require 'shinq/configuration'
6
7
  require 'serverengine'
7
8
 
@@ -27,11 +28,11 @@ module Shinq
27
28
  opts[:daemonize] = v
28
29
  end
29
30
 
30
- opt.on('--worker value', 'Name of worker class') do |v|
31
+ opt.on('-w', '--worker value', 'Name of worker class') do |v|
31
32
  opts[:worker_name] = v
32
33
  end
33
34
 
34
- opt.on('--process VALUE', 'Number of workers') do |v|
35
+ opt.on('-p', '--process VALUE', 'Number of workers') do |v|
35
36
  opts[:process] = v.to_i
36
37
  end
37
38
 
@@ -39,7 +40,7 @@ module Shinq
39
40
  opts[:queue_timeout] = v.to_i
40
41
  end
41
42
 
42
- opt.on('--db-config VALUE', 'Specify configuration file') do |v|
43
+ opt.on('--db-config VALUE', 'Specify database configuration file') do |v|
43
44
  raise OptionParseError, "#{v} does not exist" unless File.exist?(v)
44
45
  opts[:db_config] = YAML.load_file(v)
45
46
  end
@@ -49,10 +50,14 @@ module Shinq
49
50
  opts[:queue_db] = v
50
51
  end
51
52
 
52
- opt.on('--require VALUE', 'Add require path') do |v|
53
+ opt.on('-r', '--require VALUE', 'Add require path') do |v|
53
54
  opts[:require] = v
54
55
  end
55
56
 
57
+ opt.on('-s', '--statistics VALUE', 'Display queue statistics interval time(sec)') do |v|
58
+ opts[:statistics] = v.to_i
59
+ end
60
+
56
61
  opt.on('-v', '--version', 'Print version') do |v|
57
62
  puts "Shinq #{Shinq::VERSION}"
58
63
  exit(0)
@@ -82,7 +87,9 @@ module Shinq
82
87
  end
83
88
 
84
89
  def run
85
- se = ServerEngine.create(nil, Shinq::Launcher, {
90
+ klass = !options.statistics.nil? && options.statistics ? Shinq::Statistics : Shinq::Launcher
91
+
92
+ se = ServerEngine.create(nil, klass, {
86
93
  daemonize: options.daemonize,
87
94
  worker_type: 'process',
88
95
  pid_file: 'shinq.pid',
@@ -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
5
+ attr_accessor :require, :worker_name, :db_config, :queue_db, :default_db, :process, :queue_timeout, :daemonize, :statistics
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).each do |k|
15
+ %i(require worker_name db_config queue_db default_db process queue_timeout daemonize statistics).each do |k|
16
16
  send(:"#{k}=", opts[k] || DEFAULT[k])
17
17
  end
18
18
  end
@@ -0,0 +1,17 @@
1
+ require 'shinq/client'
2
+ require 'active_support/inflector'
3
+
4
+ module Shinq
5
+ module Statistics
6
+ def run
7
+ until @stop
8
+ p Shinq::Client.queue_stats(table_name: Shinq.configuration.worker_name.pluralize)
9
+ sleep Shinq.configuration.statistics
10
+ end
11
+ end
12
+
13
+ def stop
14
+ @stop = true
15
+ end
16
+ end
17
+ 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.2.0'
7
+ spec.version = '0.3.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.}
@@ -13,6 +13,7 @@ describe Shinq::Configuration do
13
13
  it { is_expected.to respond_to(:process) }
14
14
  it { is_expected.to respond_to(:queue_timeout) }
15
15
  it { is_expected.to respond_to(:daemonize) }
16
+ it { is_expected.to respond_to(:statistics) }
16
17
  end
17
18
 
18
19
  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.2.0
4
+ version: 0.3.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-10 00:00:00.000000000 Z
11
+ date: 2014-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -190,6 +190,7 @@ files:
190
190
  - lib/shinq/configuration.rb
191
191
  - lib/shinq/launcher.rb
192
192
  - lib/shinq/rails.rb
193
+ - lib/shinq/statistics.rb
193
194
  - shinq.gemspec
194
195
  - spec/config/database.yml
195
196
  - spec/integration_spec.rb