bmc-daemon-lib 0.7.4 → 0.8.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: 890ecad3eb7c2e42b23f289d50ffd7700d92c3aa
4
- data.tar.gz: 42ee986b642385630e0d65f0783502985d970217
3
+ metadata.gz: 7357ca31777d1e1c08aba18cca42f68f41094dbf
4
+ data.tar.gz: c39322bb7e140fa19a06697aa7ca5c16945721aa
5
5
  SHA512:
6
- metadata.gz: 08a925455e322261535e6969b6ad22ef76602a16548434fe05e7b97c95de884456bd8d8713953025be1f91f0d6b3c97e2ba82c39d8e76a5c0f965502f220dab3
7
- data.tar.gz: e0930fe378e1c4105a7e22a658d4617c86e99064b9b6578d3dabf73ba7fe3028b48b7fb93b2e1f244724873d945571efc6ec23dfaa2b6aa6f229561b74f7f13a
6
+ metadata.gz: c9b89de735c85cae26e6d60f51be0d89044fb382cd06ccf9bac18a67126c9f2447490a4ae13c1368aab7656fd835ba39400a9a5b3c998f1f50d73b4becd97e52
7
+ data.tar.gz: 054ebf6c828545e658cbe275054b8e5eb1722be24a3ede634e4f7d8fb121daa33697038a53522f7081c893710347c0a9e7711ce2c54e0faadda5e5dbd9c87cfa
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bmc-daemon-lib (0.7.4)
4
+ bmc-daemon-lib (0.8.0)
5
5
  chamber (~> 2.9.1)
6
6
 
7
7
  GEM
@@ -11,8 +11,8 @@ GEM
11
11
  chamber (2.9.1)
12
12
  hashie (~> 3.3)
13
13
  thor (~> 0.19.1)
14
- diff-lcs (1.2.5)
15
- hashie (3.4.6)
14
+ diff-lcs (1.3)
15
+ hashie (3.5.1)
16
16
  parser (2.3.3.1)
17
17
  ast (~> 2.2)
18
18
  powerpack (0.1.1)
@@ -31,7 +31,7 @@ GEM
31
31
  diff-lcs (>= 1.2.0, < 2.0)
32
32
  rspec-support (~> 3.5.0)
33
33
  rspec-support (3.5.0)
34
- rubocop (0.47.0)
34
+ rubocop (0.47.1)
35
35
  parser (>= 2.3.3.1, < 3.0)
36
36
  powerpack (~> 0.1)
37
37
  rainbow (>= 1.99.1, < 3.0)
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  # Project version
4
- spec.version = "0.7.4"
4
+ spec.version = "0.8.0"
5
5
 
6
6
  # Project description
7
7
  spec.name = "bmc-daemon-lib"
@@ -26,8 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "rubocop"
27
27
  #spec.add_development_dependency "pry"
28
28
 
29
-
30
-
31
29
  # Runtime dependencies
32
30
  spec.add_runtime_dependency "chamber" , "~> 2.9.1"
33
31
  end
@@ -7,9 +7,12 @@ require "time"
7
7
 
8
8
  # Project's libs
9
9
  require_relative "bmc-daemon-lib/conf"
10
+
10
11
  require_relative "bmc-daemon-lib/logger"
11
12
  require_relative "bmc-daemon-lib/logger_helper"
12
13
  require_relative "bmc-daemon-lib/logger_pool"
13
- require_relative "bmc-daemon-lib/worker_base"
14
+
15
+ require_relative "bmc-daemon-lib/worker"
16
+
14
17
  require_relative "bmc-daemon-lib/mq_endpoint"
15
18
  require_relative "bmc-daemon-lib/mq_consumer"
@@ -1,7 +1,16 @@
1
1
  module BmcDaemonLib
2
- class WorkerBase
2
+ class Worker
3
3
  include LoggerHelper
4
4
 
5
+ # Statuses
6
+ STATUS_STARTING = "starting"
7
+ STATUS_READY = "ready"
8
+ STATUS_WORKING = "working"
9
+ STATUS_SLEEPING = "sleeping"
10
+ STATUS_FINISHED = "finished"
11
+ STATUS_CRASHED = "crashed"
12
+ STATUS_TIMEOUT = "timeout"
13
+
5
14
  # Class options
6
15
  attr_reader :pool
7
16
  attr_reader :wid
@@ -18,7 +27,7 @@ module BmcDaemonLib
18
27
  Thread.current.thread_variable_set :wid, (@wid = wid)
19
28
  Thread.current.thread_variable_set :pool, (@pool = pool)
20
29
  Thread.current.thread_variable_set :started_at, Time.now
21
- worker_status WORKER_STATUS_STARTING
30
+ worker_status STATUS_STARTING
22
31
 
23
32
  # Ask worker to init itself, and return if there are errors
24
33
  if worker_init_result = worker_init
@@ -41,15 +50,35 @@ module BmcDaemonLib
41
50
  def worker_config
42
51
  end
43
52
 
53
+ def worker_sleep seconds
54
+ return if seconds.nil? || seconds.to_f == 0.0
55
+ worker_status STATUS_SLEEPING
56
+ log_info "worker_sleep: #{seconds}", @config
57
+ sleep seconds
58
+ end
59
+
60
+ def working_on_job(job, working_on_it = false)
61
+ if working_on_it
62
+ job.wid = Thread.current.thread_variable_get :wid
63
+ Thread.current.thread_variable_set :jid, job.id
64
+ else
65
+ job.wid = nil
66
+ Thread.current.thread_variable_set :jid, nil
67
+ end
68
+ end
69
+
44
70
  def start_loop
45
71
  log_info "start_loop starting", @config
46
72
  loop do
47
73
  begin
74
+ # Announce we're waiting for work
75
+ worker_status STATUS_READY
76
+
48
77
  # Do the hard work
49
78
  worker_process
50
79
 
51
- # Do the cleaning/sleeping stuff
52
- worker_after
80
+ # Should we sleep ?
81
+ worker_sleep @config[:timer]
53
82
 
54
83
  rescue StandardError => e
55
84
  log_error "WORKER EXCEPTION: #{e.inspect}"
@@ -58,7 +87,7 @@ module BmcDaemonLib
58
87
  end
59
88
  end
60
89
 
61
- def worker_status status, job = nil
90
+ def worker_status status
62
91
  # Update thread variables
63
92
  Thread.current.thread_variable_set :status, status
64
93
  Thread.current.thread_variable_set :updated_at, Time.now
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bmc-daemon-lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno MEDICI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-17 00:00:00.000000000 Z
11
+ date: 2017-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -101,7 +101,7 @@ files:
101
101
  - lib/bmc-daemon-lib/logger_pool.rb
102
102
  - lib/bmc-daemon-lib/mq_consumer.rb
103
103
  - lib/bmc-daemon-lib/mq_endpoint.rb
104
- - lib/bmc-daemon-lib/worker_base.rb
104
+ - lib/bmc-daemon-lib/worker.rb
105
105
  homepage: http://github.com/bmedici/bmc-daemon-lib
106
106
  licenses:
107
107
  - MIT