shinq 1.0.0.rc1 → 1.0.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: 64209cd09dc412fa47ad5de740fdc48a1a4882a6
4
- data.tar.gz: ac63880ed26db5f5c417d068a1a5ca6c71d76cd5
3
+ metadata.gz: a67651195e68cb9fb0f5ee0cb98db58a40ecdcb7
4
+ data.tar.gz: 14f7f91d02b1ea4e3cc4035cd30ff073058fd926
5
5
  SHA512:
6
- metadata.gz: c55c274a6a76c8397cf344f10d8a1f692cea198e2c4f92474077771736f1f051f688334753da31d8f6c803b43cf43925ec6c05078bdff105e5d53503bff357a1
7
- data.tar.gz: 611ff43357eeeef74737ed6d67432d706b2e0a10ad8746c224f2fddc786fe5425f8169faa4597eebebf17f663ac8de06a022b4be7b8ec32d9fa1d637f7048544
6
+ metadata.gz: dbd5b976361080d37a57f8fa392017624f91610ee67814cfad83e1e8fe46be779cd07b22dff8d0921a5593f95100d5f2a2dbd9f7bd666d7a19bdf9e429b05eeb
7
+ data.tar.gz: b18f064fee0b01b968791d31370a44fa7d95fbd95d9b1360dd0bc4e25b508b0e998553b850f298aabbc287bbfde3b1c1ea5132c448939042dabc22057f86122c
data/.travis.yml CHANGED
@@ -12,5 +12,6 @@ rvm:
12
12
  gemfile:
13
13
  - Gemfile
14
14
  before_install:
15
+ - gem update bundler
15
16
  - mysql -e "create database IF NOT EXISTS shinq_test;" -uroot
16
17
  script: bundle exec rspec
data/lib/shinq/cli.rb CHANGED
@@ -73,6 +73,10 @@ module Shinq
73
73
  opts[:abort_on_error] = v
74
74
  end
75
75
 
76
+ opt.on('--sleep-sec-on-error N', Integer, 'Allow worker to sleep(sec) after exception') do |v|
77
+ opts[:sleep_sec_on_error] = v
78
+ end
79
+
76
80
  opt.on('-v', '--version', 'Print version') do |v|
77
81
  puts "Shinq #{Shinq::VERSION}"
78
82
  exit(0)
@@ -10,7 +10,7 @@ module Shinq
10
10
  # You may need to set it +false+ for jobs which take very long time to proceed.
11
11
  # You may also need to handle performing error manually then.
12
12
  class Configuration
13
- attr_accessor :require, :worker_name, :db_config, :queue_db, :default_db, :process, :graceful_kill_timeout, :queue_timeout, :daemonize, :statistics, :lifecycle, :abort_on_error
13
+ attr_accessor :require, :worker_name, :db_config, :queue_db, :default_db, :process, :graceful_kill_timeout, :queue_timeout, :daemonize, :statistics, :lifecycle, :abort_on_error, :sleep_sec_on_error
14
14
 
15
15
  DEFAULT = {
16
16
  require: '.',
@@ -18,12 +18,14 @@ module Shinq
18
18
  graceful_kill_timeout: 600,
19
19
  queue_timeout: 1,
20
20
  daemonize: false,
21
- abort_on_error: true
21
+ abort_on_error: true,
22
+ sleep_sec_on_error: 1,
22
23
  }
23
24
 
24
25
  def initialize(opts)
25
- %i(require worker_name db_config queue_db default_db process queue_timeout daemonize statistics lifecycle abort_on_error).each do |k|
26
- send(:"#{k}=", opts[k] || DEFAULT[k])
26
+ %i(require worker_name db_config queue_db default_db process queue_timeout daemonize statistics lifecycle abort_on_error sleep_sec_on_error).each do |k|
27
+ value = opts.key?(k) ? opts[k] : DEFAULT[k]
28
+ send(:"#{k}=", value)
27
29
  end
28
30
  end
29
31
 
@@ -16,21 +16,26 @@ module Shinq
16
16
  @loop_count = 0
17
17
 
18
18
  until @stop
19
- queue = Shinq::Client.dequeue(table_name: worker_name.pluralize)
20
- next Shinq.logger.info("Queue is empty (#{Time.now})") unless queue
19
+ begin
20
+ queue = Shinq::Client.dequeue(table_name: worker_name.pluralize)
21
+ next Shinq.logger.info("Queue is empty (#{Time.now})") unless queue
21
22
 
22
- if Shinq.configuration.abort_on_error
23
- begin
23
+ if Shinq.configuration.abort_on_error
24
+ worker_class.new.perform(queue)
25
+ Shinq::Client.done
26
+ else
27
+ Shinq::Client.done
24
28
  worker_class.new.perform(queue)
25
- rescue => e
26
- Shinq::Client.abort
27
- raise e
28
29
  end
29
30
 
30
- Shinq::Client.done
31
- else
32
- Shinq::Client.done
33
- worker_class.new.perform(queue)
31
+ Shinq.clear_all_connections!
32
+ rescue => e
33
+ Shinq.logger.error(format_error_message(e))
34
+ sleep Shinq.configuration.sleep_sec_on_error
35
+
36
+ Shinq::Client.abort if Shinq.configuration.abort_on_error && queue
37
+ Shinq.clear_all_connections!
38
+ break
34
39
  end
35
40
 
36
41
  @loop_count += 1
@@ -50,5 +55,16 @@ module Shinq
50
55
  return false unless Shinq.configuration.lifecycle
51
56
  return (Shinq.configuration.lifecycle < @loop_count)
52
57
  end
58
+
59
+ private
60
+
61
+ def format_error_message(error)
62
+ if defined?(::Rails) && ::Rails.backtrace_cleaner
63
+ backtrace = ::Rails.backtrace_cleaner.clean(error.backtrace || []).presence || error.backtrace
64
+ else
65
+ backtrace = error.backtrace
66
+ end
67
+ "#{error.message} at #{backtrace.join(' <<< ')}"
68
+ end
53
69
  end
54
70
  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 = '1.0.0.rc1'
7
+ spec.version = '1.0.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: 1.0.0.rc1
4
+ version: 1.0.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: 2017-08-28 00:00:00.000000000 Z
11
+ date: 2017-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -251,9 +251,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
251
251
  version: '0'
252
252
  required_rubygems_version: !ruby/object:Gem::Requirement
253
253
  requirements:
254
- - - ">"
254
+ - - ">="
255
255
  - !ruby/object:Gem::Version
256
- version: 1.3.1
256
+ version: '0'
257
257
  requirements: []
258
258
  rubyforge_project:
259
259
  rubygems_version: 2.6.8