assistor 0.1.0 → 0.2.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
- SHA1:
3
- metadata.gz: 076ce5c505b2401756f570d5cd6d7029620d5f8c
4
- data.tar.gz: 8f0aa2a897cd547bb6d816809fdc1f57a8926ffb
2
+ SHA256:
3
+ metadata.gz: 1fa2ddaa11e30636eb624ee437c724f2a1602fdf4951cf386d1039ccc7b4d664
4
+ data.tar.gz: 52f0e901cb875e920d43e677592f11dd4f20b045f7dd8752b95f5dd20c9a23e4
5
5
  SHA512:
6
- metadata.gz: 00b36cf07fd1bec003667a0d2fd5e78d426eb1af3ffaa8b90410fda844b4baf1fb406c67e3a9a86f18ed21a9bf4478c72ccb441839a5f2d2ad629a8b8bce83ba
7
- data.tar.gz: 96745595c9bb58ffe73c0a065213775ca501d5ccd3603c5010e5ff2b489833b1c11f5be9a0dabe4faff771e7ba0ec5d4af43dd8c1d8d7fb1c8982d0f22a32e83
6
+ metadata.gz: 2c5f78349106336a9716bb07ab1835309ae587b9aef14da0a9bb9c84aabb4183e480a0f667e651d8fa2f3759178573084ae4bad7d1223cc4ea67086cb5b2a77b
7
+ data.tar.gz: e0d5c02282a5929a2e5e0f89bb09ba1c77b084b6c168dc4b6a0dda723ac0ccee2c8c38d1ea2f44f5b03bd81fe9978bf3be924d645b825962fbec6634f89778e7
data/README.md CHANGED
@@ -48,10 +48,6 @@ class ExampleJob < Assistor::AbstractJob
48
48
  def run
49
49
  sleep @i
50
50
  end
51
-
52
- def fail(exception)
53
- ExceptionHandler.handle exception
54
- end
55
51
  end
56
52
 
57
53
  class ExampleQueue < Assistor::AbstractQueue
@@ -77,6 +73,7 @@ configuration = Assistor::Configuration.new
77
73
  configuration.id = 'example'
78
74
  configuration.size = 3
79
75
  configuration.delay = 0.2
76
+ configuration.exception_handler = Proc.new { |exception| ExceptionHandler.handle(exception) }_
80
77
  configuration.log_file = File.join(File.expand_path('..', __FILE__), 'example.log')
81
78
  configuration.pid_file = File.join(File.expand_path('..', __FILE__), 'example.pid')
82
79
 
@@ -7,9 +7,5 @@ module Assistor
7
7
  def run
8
8
  raise NotImplementedError
9
9
  end
10
-
11
- def fail(exception)
12
- raise NotImplementedError
13
- end
14
10
  end
15
11
  end
@@ -48,7 +48,7 @@ module Assistor
48
48
  with_pid_file { @job.run }
49
49
  rescue => e
50
50
  log_file.error e
51
- @job.fail e
51
+ @configuration.exception_handler.call(e)
52
52
  end
53
53
 
54
54
  def stop
@@ -106,7 +106,7 @@ module Assistor
106
106
  def with_pid_file
107
107
  pid_file.create Process.pid
108
108
  yield
109
- pid_file.delete pid_file
109
+ pid_file.delete
110
110
  end
111
111
  end
112
112
  end
@@ -44,7 +44,7 @@ module Assistor
44
44
  end
45
45
 
46
46
  def decrease
47
- @size -= 1
47
+ @size -= 1 if @size > 0
48
48
  end
49
49
  end
50
50
  end
@@ -10,5 +10,13 @@ module Assistor
10
10
  def pid_file=(file)
11
11
  @pid_file = PidFile.new file
12
12
  end
13
+
14
+ def exception_handler(exception_handler)
15
+ @exception_handler = exception_handler
16
+ end
17
+
18
+ def exception_handler
19
+ @exception_handler || Proc.new {}
20
+ end
13
21
  end
14
22
  end
@@ -17,9 +17,9 @@ module Assistor
17
17
  loop do
18
18
  sleep(delay) unless assist(queue)
19
19
  end
20
- stop
21
20
  rescue => e
22
21
  log_file.error e
22
+ @configuration.exception_handler.call(e)
23
23
  end
24
24
 
25
25
  private
@@ -39,6 +39,7 @@ module Assistor
39
39
  exit!(0)
40
40
  rescue => e
41
41
  log_file.error e
42
+ @configuration.exception_handler.call(e)
42
43
  end
43
44
 
44
45
  def stop!
@@ -48,6 +49,7 @@ module Assistor
48
49
  exit!(1)
49
50
  rescue => e
50
51
  log_file.error e
52
+ @configuration.exception_handler.call(e)
51
53
  end
52
54
 
53
55
  def assist(queue)
@@ -61,6 +63,7 @@ module Assistor
61
63
  assistant_group.add(assistant)
62
64
  rescue => e
63
65
  log_file.error e
66
+ @configuration.exception_handler.call(e)
64
67
  end
65
68
 
66
69
  def daemonize
@@ -1,3 +1,3 @@
1
1
  module Assistor
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/lib/assistor.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'logger'
2
2
  require 'tmpdir'
3
+ require 'forwardable'
4
+ require 'securerandom'
3
5
 
4
6
  require 'assistor/version'
5
7
  require 'assistor/log_file'
metadata CHANGED
@@ -1,71 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assistor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomasz Kowalewski
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-31 00:00:00.000000000 Z
11
+ date: 2023-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.13'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.13'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
55
- - !ruby/object:Gem::Dependency
56
- name: rubocop
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 0.44.1
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 0.44.1
54
+ version: '0'
69
55
  description: Simple background processing framework for Ruby
70
56
  email:
71
57
  - me@tkowalewski.pl
@@ -91,7 +77,7 @@ homepage: https://github.com/tkowalewski/assistor
91
77
  licenses:
92
78
  - MIT
93
79
  metadata: {}
94
- post_install_message:
80
+ post_install_message:
95
81
  rdoc_options: []
96
82
  require_paths:
97
83
  - lib
@@ -106,9 +92,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
92
  - !ruby/object:Gem::Version
107
93
  version: '0'
108
94
  requirements: []
109
- rubyforge_project:
110
- rubygems_version: 2.5.1
111
- signing_key:
95
+ rubygems_version: 3.1.2
96
+ signing_key:
112
97
  specification_version: 4
113
98
  summary: Simple background processing framework for Ruby
114
99
  test_files: []