dynarex_cron 0.2.4 → 0.2.5

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: 8cbd72788d4dcd778c062456b222c9c35640d23e
4
- data.tar.gz: fd9760125e7972e2023852c40f0e816093934a76
3
+ metadata.gz: c96a52e108c3548cfdd0ace9597459948c3f3f0d
4
+ data.tar.gz: 80b2145ba25bc05a262f12d51afa7ac0c54597f0
5
5
  SHA512:
6
- metadata.gz: 0295274d8bf32d1ad18c4d22eb43f74d8b5950cc1ac2cea5b1398c95e8875b80c866f449fa00be315874784e77fe3abb6d16e1c6a6066c409613b3b07f2a00ae
7
- data.tar.gz: b731ef83679628ba8dd04c3b365b7ede63a037b12eb180564f996cca6572c6287290cfdf9ce5bc6e25b0a943c81e4ec22a5446361eb261607198b9437fef0cbf
6
+ metadata.gz: 571ebc4a746d47f3985fbd4885570be16c82351eee94f0cec70611861eceb80577677586b65cc00500bb0b34f8ae625fad505c80c312d732023d74059675a054
7
+ data.tar.gz: e20579ba72f4ea5bfbe8cc630e2c497dd47aa63944762015e6f28b6546b73b11b39ce9955ed3eb754828bba89529a95a9c471f2a193751c4bf61d9f82cb32756
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/dynarex_cron.rb CHANGED
@@ -13,9 +13,11 @@ DF = "%Y-%m-%d %H:%M"
13
13
 
14
14
  class DynarexCron
15
15
 
16
+ # options: e.g. sps_address, 'sps', drb_server: 57000
17
+ #
16
18
  def initialize(dynarex_file=nil, options={})
17
19
 
18
- opt = {sps_address: nil, drb_server: false, log: nil}.merge options
20
+ opt = {sps_address: nil, drb_server: nil, log: nil}.merge options
19
21
  @logger = Logger.new(opt[:log],'weekly') if opt[:log]
20
22
 
21
23
  @cron_entries, @cron_events = [], []
@@ -26,12 +28,12 @@ class DynarexCron
26
28
 
27
29
  @sps_address = opt[:sps_address]
28
30
 
29
- if opt[:drb_server] == true then
31
+ if opt[:drb_server] then
30
32
 
31
33
  Thread.new {
32
34
 
33
35
  # start up the DRb service
34
- DRb.start_service 'druby://:57000', self
36
+ DRb.start_service 'druby://:' + opt[:drb_server], self
35
37
 
36
38
  # wait for the DRb service to finish before exiting
37
39
  DRb.thread.join
@@ -124,27 +126,30 @@ class DynarexCron
124
126
 
125
127
  end
126
128
 
129
+
127
130
  class DynarexEvents < DynarexCron
128
131
 
129
132
  attr_reader :to_a
130
133
 
134
+ # options: e.g. sps_address, 'sps', drb_server: 58000
135
+ #
131
136
  def initialize(dynarex_file=nil, options={})
132
137
 
133
- opt = {sps_address: nil, drb_server: false}.merge options
134
-
135
- @cron_events = []
138
+ opt = {sps_address: nil, drb_server: nil}.merge options
136
139
 
140
+ @entries, @cron_events = [], []
141
+
137
142
  @dynarex_file = dynarex_file
138
143
  load_events()
139
144
 
140
145
  @sps_address = opt[:sps_address]
141
146
 
142
- if opt[:drb_server] == true then
143
-
147
+ if opt[:drb_server] then
148
+
144
149
  Thread.new {
145
150
 
146
151
  # start up the DRb service
147
- DRb.start_service 'druby://:57500', self
152
+ DRb.start_service 'druby://:' + opt[:drb_server], self
148
153
 
149
154
  # wait for the DRb service to finish before exiting
150
155
  DRb.thread.join
@@ -152,11 +157,18 @@ class DynarexEvents < DynarexCron
152
157
  end
153
158
  end
154
159
 
160
+ def add_entry(h)
161
+ # if the entry already exists delete it
162
+ @entries.delete @entries.find {|x| x[:job] == h[:job]}
163
+ @entries << h
164
+ end
165
+
155
166
  def load_events()
156
167
 
157
168
  dynarex = Dynarex.new @dynarex_file
158
- @entries = dynarex.to_h
159
- @cron_events = self.to_a
169
+ @entries = dynarex.to_h || @entries
170
+ @cron_events = self.to_a if @entries
171
+ 'events loaded and refreshed'
160
172
  end
161
173
 
162
174
  alias refresh load_events
@@ -172,16 +184,17 @@ class DynarexEvents < DynarexCron
172
184
  end
173
185
 
174
186
  def to_a()
175
-
187
+
188
+ return unless @entries
189
+
176
190
  @entries.inject([]) do |r,h|
177
191
 
178
- h[:cron] = ChronicCron.new(h[:date])
179
- h[:job] = 'pub event: ' + h[:title]
192
+ h[:cron] = ChronicCron.new(h[:date] + ' ' + h[:recurring].to_s )
193
+ h[:job] ||= 'pub event: ' + h[:title]
180
194
 
181
- if h[:reminder].length > 0 then
195
+ if h[:reminder].to_s.length > 0 then
182
196
  rmndr = {}
183
- rmndr[:cron] = ChronicCron.new((Chronic.parse(h[:date]) -
184
- ChronicDuration.parse(h[:reminder])).to_s)
197
+ rmndr[:cron] = ChronicCron.new((Chronic.parse(h[:date]) - ChronicDuration.parse(h[:reminder])).to_s)
185
198
  rmndr[:job] = 'pub event: reminder ' + h[:title]
186
199
  r << rmndr
187
200
  end
@@ -190,4 +203,4 @@ class DynarexEvents < DynarexCron
190
203
  end
191
204
 
192
205
  end
193
- end
206
+ 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.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,76 +31,76 @@ cert_chain:
31
31
  y6cNz+NnybgoQfG28NcwV1e/31NTJk5VqdKHKnTfPcp/y35T9YoElNn5cSs93qc5
32
32
  U5VVkvsVQudaZw==
33
33
  -----END CERTIFICATE-----
34
- date: 2013-08-14 00:00:00.000000000 Z
34
+ date: 2013-10-26 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: dynarex
38
38
  requirement: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - '>='
40
+ - - ">="
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - '>='
47
+ - - ">="
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: chronic_cron
52
52
  requirement: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - '>='
54
+ - - ">="
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  type: :runtime
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - '>='
61
+ - - ">="
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: simplepubsub
66
66
  requirement: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - '>='
68
+ - - ">="
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  type: :runtime
72
72
  prerelease: false
73
73
  version_requirements: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - '>='
75
+ - - ">="
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: rscript
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - '>='
82
+ - - ">="
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  type: :runtime
86
86
  prerelease: false
87
87
  version_requirements: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - '>='
89
+ - - ">="
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: chronic_duration
94
94
  requirement: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - '>='
96
+ - - ">="
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  type: :runtime
100
100
  prerelease: false
101
101
  version_requirements: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - '>='
103
+ - - ">="
104
104
  - !ruby/object:Gem::Version
105
105
  version: '0'
106
106
  description:
@@ -120,12 +120,12 @@ require_paths:
120
120
  - lib
121
121
  required_ruby_version: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - '>='
123
+ - - ">="
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  requirements:
128
- - - '>='
128
+ - - ">="
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
131
  requirements: []
metadata.gz.sig CHANGED
Binary file