shinq 0.6.0 → 0.7.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: 775e97f7be5e8a0af51289776fb5f80452272fab
4
- data.tar.gz: cff7b9411652a96f51b09e8728196053d8e495c7
3
+ metadata.gz: 655d145ff88397bca387abccd196c36888428e21
4
+ data.tar.gz: 41df3f27cc6b3af3fa50a5fa2d3d0ab0da24293d
5
5
  SHA512:
6
- metadata.gz: 9e647a7d1a3e1ae6650e2b41e202fa78f7342592a630ac47c5e2bb7f58dceb809b74a5c1d5cdfbd448af25135f1ea652a0de81416c7c3fe75d54518683f8c935
7
- data.tar.gz: d40da827e5b1a620a245dd9764a459eb9603641c539054d837a8d08fa1ff5d09f6f417643dc94cb66f0a0fde47848b93502fba07d2499938cf5bf438befd9e6c
6
+ metadata.gz: 10c3396b0201a6d678c8be2fb172c885e58ef13a14c56ffc7f5c4af37f95e9af579c60bda6a3236112bf3b95fd98d27ac4b07f88fc2250736a7b964113aa77c8
7
+ data.tar.gz: 6307bd0ce80f84e26b4e9cbfd11f2e463ba9f933bffa3149d9f275117bb5103ebf9174a7d632d6f83445516f10699ed91e2eef20accaefb2882e0df9e117e667
data/lib/shinq/cli.rb CHANGED
@@ -63,6 +63,10 @@ module Shinq
63
63
  opts[:statistics] = v.to_i
64
64
  end
65
65
 
66
+ opt.on('--[no-]abort-on-error', 'Abort ') do |v|
67
+ opts[:abort_on_error] = v
68
+ end
69
+
66
70
  opt.on('-v', '--version', 'Print version') do |v|
67
71
  puts "Shinq #{Shinq::VERSION}"
68
72
  exit(0)
@@ -1,18 +1,27 @@
1
1
  module Shinq
2
2
  class ConfigurationError < StandardError; end
3
3
 
4
+ # @!attribute abort_on_error
5
+ # @return [Boolean] Whether do +queue_abort()+ on performing failure.
6
+ # @see Shinq::Launcher#run
7
+ #
8
+ # Defaults to +true+, which means that worker do +queue_end()+ AFTER it proceeds a job.
9
+ # If it is +false+, worker do +queue_end()+ BEFORE it proceeds a job.
10
+ # You may need to set it +false+ for jobs which take very long time to proceed.
11
+ # You may also need to handle performing error manually then.
4
12
  class Configuration
5
- attr_accessor :require, :worker_name, :db_config, :queue_db, :default_db, :process, :queue_timeout, :daemonize, :statistics, :lifecycle
13
+ attr_accessor :require, :worker_name, :db_config, :queue_db, :default_db, :process, :queue_timeout, :daemonize, :statistics, :lifecycle, :abort_on_error
6
14
 
7
15
  DEFAULT = {
8
16
  require: '.',
9
17
  process: 1,
10
18
  queue_timeout: 1,
11
- daemonize: false
19
+ daemonize: false,
20
+ abort_on_error: true
12
21
  }
13
22
 
14
23
  def initialize(opts)
15
- %i(require worker_name db_config queue_db default_db process queue_timeout daemonize statistics lifecycle).each do |k|
24
+ %i(require worker_name db_config queue_db default_db process queue_timeout daemonize statistics lifecycle abort_on_error).each do |k|
16
25
  send(:"#{k}=", opts[k] || DEFAULT[k])
17
26
  end
18
27
  end
@@ -3,6 +3,8 @@ require 'active_support/inflector'
3
3
 
4
4
  module Shinq
5
5
  module Launcher
6
+ # Wait configured queue and proceed each of them until stop.
7
+ # @see Shinq::Configuration#abort_on_error
6
8
  def run
7
9
  worker_name = Shinq.configuration.worker_name
8
10
  worker_class = worker_name.camelize.constantize
@@ -13,15 +15,20 @@ module Shinq
13
15
  queue = Shinq::Client.dequeue(table_name: worker_name.pluralize)
14
16
  next Shinq.logger.info("Queue is empty (#{Time.now})") unless queue
15
17
 
16
- begin
18
+ if Shinq.configuration.abort_on_error
19
+ begin
20
+ worker_class.new.perform(queue)
21
+ rescue => e
22
+ Shinq::Client.abort
23
+ raise e
24
+ end
25
+
26
+ Shinq::Client.done
27
+ else
28
+ Shinq::Client.done
17
29
  worker_class.new.perform(queue)
18
- rescue => e
19
- Shinq::Client.abort
20
- raise e
21
30
  end
22
31
 
23
- Shinq::Client.done
24
-
25
32
  @loop_count += 1
26
33
 
27
34
  if lifecycle_limit?
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.6.0'
7
+ spec.version = '0.7.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.}
@@ -15,6 +15,7 @@ describe Shinq::Configuration do
15
15
  it { is_expected.to respond_to(:daemonize) }
16
16
  it { is_expected.to respond_to(:statistics) }
17
17
  it { is_expected.to respond_to(:lifecycle) }
18
+ it { is_expected.to respond_to(:abort_on_error) }
18
19
  end
19
20
 
20
21
  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.6.0
4
+ version: 0.7.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: 2016-11-01 00:00:00.000000000 Z
11
+ date: 2017-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler