dynarex_cron 0.8.4 → 0.9.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: c23f02febf1feaaf6bc8d7a23404310c896ecba5
4
- data.tar.gz: 5202e38c98442d9a0c95278d5c13c247c86fe007
3
+ metadata.gz: 0d94bcaf6e26c355a32180f1e68a27b5e73ecff6
4
+ data.tar.gz: a99e0a754a774080e80b4c4d2a2255d2ab8984ad
5
5
  SHA512:
6
- metadata.gz: 0b67822d7e522deddbce8d3154e1821468cececd01d934dc2930565014d6b66e224e11c21cb839bce51ff219a6ef86b7912ba2e7b714aad795429b8604c7a2b1
7
- data.tar.gz: 4579c0bef8e73f2a9b1cde33ec5c6b21ddf418eed3b285c9eaa933eb4ebf3ec52aa6bfabefe31180876e59fa3bf894dcec97cb8076c78f14e546cffadb5636b4
6
+ metadata.gz: da312335793f100c883a7fac0bb024a057b7f75b242acbd96e6014d51c3e3c371e797472a0de93724fcac4f2d22bd008f8d3abfdb542cb2cae0eb048df9e1a6e
7
+ data.tar.gz: bfe43b8ba27d6db1c939c8d7b929a3844e15e71a711d36ffd1e528e495c705e4779cec229e67d9936eb948d7018bdf3dac2f48401fa8a138f917a4f7faf76e54
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/dynarex_cron.rb CHANGED
@@ -5,7 +5,6 @@
5
5
  require 'dynarex'
6
6
  require 'chronic_cron'
7
7
  require 'sps-pub'
8
- require 'logger'
9
8
 
10
9
 
11
10
  DF = "%Y-%m-%d %H:%M"
@@ -14,37 +13,38 @@ class DynarexCron
14
13
 
15
14
  # options: e.g. sps_address: 'sps', sps_port: '59000'
16
15
  #
17
- def initialize(dynarex_file=nil, options={})
16
+ def initialize(dxfile=nil, sps_address: 'sps', sps_port: '59000', \
17
+ log: nil, time_offset: 0)
18
18
 
19
- opt = {sps_address: 'sps', sps_port: '59000', \
20
- log: nil, time_offset: 0}.merge options
21
- @logger = Logger.new(opt[:log],'weekly') if opt[:log]
19
+
20
+ @dxfile, @sps_address, @sps_port, @log = dxfile, sps_address, sps_port, log
22
21
 
23
22
  # time_offset: used for testing a cron entry without having to change
24
23
  # the time of each entry
25
- @time_offset = opt[:time_offset].to_i
24
+ @time_offset = time_offset.to_i
26
25
 
27
26
  @cron_entries = []
28
27
 
29
- @dynarex_file = dynarex_file
30
28
 
31
- if @dynarex_file then
29
+ if @dxfile then
32
30
 
33
- dynarex = load_doc dynarex_file
31
+ dynarex = load_doc dxfile
34
32
  load_entries(dynarex)
35
33
  end
36
34
 
37
- @sps_address, @sps_port = opt[:sps_address], opt[:sps_port]
38
- @pub = SPSPub.new address: @sps_address, port: @sps_port
35
+ @pub = SPSPub.new address: sps_address, port: sps_port
39
36
 
40
37
  end
41
38
 
42
39
  def start
43
40
 
44
41
  @running = true
45
- puts '[' + (Time.now + @time_offset).strftime(DF) + '] DynarexCron started'
46
- params = {uri: "ws://%s:%s" % [@sps_address, @sps_port]}
47
42
 
43
+ if @log then
44
+ @log.info 'DynarexCron/start: Time.now: ' \
45
+ + (Time.now + @time_offset).strftime(DF)
46
+ end
47
+
48
48
 
49
49
  sleep 1 until Time.now.sec == 0
50
50
 
@@ -53,12 +53,12 @@ class DynarexCron
53
53
 
54
54
  iterate @cron_entries
55
55
 
56
- if @dynarex_file.is_a? String then
56
+ if @dxfile.is_a? String then
57
57
 
58
- # What happens if the @dynarex_file is a URL and the web server is
58
+ # What happens if the @dxfile is a URL and the web server is
59
59
  # temporarily unavailable? i.e. 503 Service Temporarily Unavailable
60
60
  begin
61
- buffer, _ = RXFHelper.read(@dynarex_file)
61
+ buffer, _ = RXFHelper.read(@dxfile)
62
62
  reload_entries buffer if @buffer != buffer
63
63
  rescue
64
64
  puts 'dynarex_cron: warning: ' + ($!).inspect
@@ -103,27 +103,35 @@ class DynarexCron
103
103
  end
104
104
  end
105
105
 
106
- def log(s, method_name=:debug)
107
- return unless @logger
108
- @logger.method(method_name).call s
109
- end
110
106
 
111
107
  def iterate(cron_entries)
112
108
 
113
109
  cron_entries.each do |h|
114
110
 
115
111
  datetime = (Time.now + @time_offset).strftime(DF)
112
+ @log.info 'DynarexCron/iterate: datetime: ' + datetime if @log
113
+ @log.info 'DynarexCron/iterate: cron.to_time: ' + h[:cron].to_time.strftime(DF) if @log
116
114
 
117
115
  if h[:cron].to_time.strftime(DF) == datetime then
118
116
 
119
117
  begin
120
118
 
121
- @pub.notice h[:fqm].gsub('!Time',Time.now.strftime("%H:%M"))
119
+ if h[:fqm].empty? and @log then
120
+ @log.debug 'DynarexCron/iterate: no h[:fqw] found ' + h.inspect
121
+ end
122
+
123
+ msg = h[:fqm].gsub('!Time',Time.now.strftime("%H:%M"))
122
124
 
123
- rescue
124
- log 'cron ' + h[:cron].inspect, :info
125
- log h.inspect + ' : ' + ($!).inspect
125
+ @pub.notice msg
126
126
 
127
+ rescue
128
+
129
+ if @log then
130
+ @log.debug 'DynarexCron/iterate: cron: ' + h[:cron].inspect
131
+ @log.debug 'DynarexCron/iterate: h: ' + h.inspect + ' : ' \
132
+ + ($!).inspect
133
+ end
134
+
127
135
  end
128
136
 
129
137
  h[:cron].next # advances the time
@@ -139,4 +147,4 @@ class DynarexCron
139
147
  @buffer = buffer
140
148
  end
141
149
 
142
- end
150
+ end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynarex_cron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  tsPyW5OuDQXshrgmPt97DD8Btg4Tg5CGwnm0aeVYC/E4PnCMrtQNyPaRwBfvGrF0
32
32
  vXqXm6nxDCrL/w==
33
33
  -----END CERTIFICATE-----
34
- date: 2017-05-29 00:00:00.000000000 Z
34
+ date: 2017-12-10 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: chronic_cron
@@ -42,7 +42,7 @@ dependencies:
42
42
  version: '0.3'
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- version: 0.3.1
45
+ version: 0.3.7
46
46
  type: :runtime
47
47
  prerelease: false
48
48
  version_requirements: !ruby/object:Gem::Requirement
@@ -52,27 +52,27 @@ dependencies:
52
52
  version: '0.3'
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: 0.3.1
55
+ version: 0.3.7
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: dynarex
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '1.5'
62
+ version: '1.7'
63
63
  - - ">="
64
64
  - !ruby/object:Gem::Version
65
- version: 1.5.26
65
+ version: 1.7.27
66
66
  type: :runtime
67
67
  prerelease: false
68
68
  version_requirements: !ruby/object:Gem::Requirement
69
69
  requirements:
70
70
  - - "~>"
71
71
  - !ruby/object:Gem::Version
72
- version: '1.5'
72
+ version: '1.7'
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 1.5.26
75
+ version: 1.7.27
76
76
  - !ruby/object:Gem::Dependency
77
77
  name: sps-pub
78
78
  requirement: !ruby/object:Gem::Requirement
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  requirements: []
122
122
  rubyforge_project:
123
- rubygems_version: 2.6.8
123
+ rubygems_version: 2.6.13
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: Publishes SimplePubSub messages by reading cron entries from a Dynarex document
metadata.gz.sig CHANGED
Binary file