dynarex_cron 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/dynarex_cron.rb +64 -13
- metadata +16 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 076ae88a768c151597d0bdda36be16d55c697ed5
|
4
|
+
data.tar.gz: 18d8493b651c6f6c09a0d58b9b3bf29efc7efa9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 947ad1e25b48eb6036116938f696e0a3e17a1f5c1c6f4fd29bcda8b693c0782b41ec221fabf97449f1494c389deda25e0e8b96043ca90198c00bb3d53f5100f7
|
7
|
+
data.tar.gz: 280e496fc0c6da71891efe6574cf2284b7454f4cbd6a98532a8a40fc73b998b50192f82dfba0ceff7b5ff7696387a54768fe4118b8866da33b776e01ae847a03
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/dynarex_cron.rb
CHANGED
@@ -6,35 +6,86 @@ require 'dynarex'
|
|
6
6
|
require 'chronic_cron'
|
7
7
|
require 'simplepubsub'
|
8
8
|
require 'rscript'
|
9
|
+
require 'dynarex-events'
|
9
10
|
|
10
11
|
DF = "%Y-%m-%d %H:%M"
|
11
12
|
|
12
13
|
class DynarexCron
|
13
14
|
|
14
|
-
def initialize(dynarex_file,
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@
|
15
|
+
def initialize(dynarex_file=nil, options={})
|
16
|
+
|
17
|
+
opt = {sps_address: nil, drb_server: false}.merge options
|
18
|
+
|
19
|
+
@cron_entries, @cron_events = [], []
|
20
|
+
|
21
|
+
@dynarex_file = dynarex_file
|
22
|
+
load_entries() if @dynarex_file
|
23
|
+
load_events() if @include_url
|
24
|
+
|
25
|
+
@sps_address = opt[:sps_address]
|
26
|
+
|
27
|
+
if opt[:drb_server] == true then
|
28
|
+
|
29
|
+
Thread.new {
|
30
|
+
|
31
|
+
# start up the DRb service
|
32
|
+
DRb.start_service 'druby://:57000', self
|
33
|
+
|
34
|
+
# wait for the DRb service to finish before exiting
|
35
|
+
DRb.thread.join
|
36
|
+
}
|
37
|
+
end
|
19
38
|
end
|
20
39
|
|
21
40
|
def start
|
41
|
+
@running = true
|
22
42
|
puts '[' + Time.now.strftime(DF) + '] DynarexCron started'
|
43
|
+
|
44
|
+
while @running == true
|
23
45
|
|
24
|
-
|
25
|
-
|
26
|
-
@cron_entries.each do |h|
|
27
|
-
if h[:cron].to_time.strftime(DF) == Time.now.strftime(DF) then
|
28
|
-
Thread.new { run(h[:job]) }
|
29
|
-
h[:cron].next # advances the time
|
30
|
-
end
|
31
|
-
end
|
46
|
+
iterate @cron_entries
|
47
|
+
iterate @cron_events
|
32
48
|
sleep 60 # wait for 60 seconds
|
33
49
|
end
|
34
50
|
end
|
51
|
+
|
52
|
+
def stop()
|
53
|
+
@running = false
|
54
|
+
end
|
55
|
+
|
56
|
+
def load_entries()
|
57
|
+
|
58
|
+
dynarex = Dynarex.new @dynarex_file
|
59
|
+
|
60
|
+
@include_url = dynarex.summary[:include]
|
61
|
+
@cron_entries = dynarex.to_h
|
62
|
+
@cron_entries.each {|h| h[:cron] = ChronicCron.new(h[:expression]) }
|
63
|
+
end
|
64
|
+
|
65
|
+
alias refresh_entries load_entries
|
66
|
+
|
67
|
+
def load_events()
|
68
|
+
|
69
|
+
de = DynarexEvents.new(@include_url)
|
70
|
+
@cron_events = de.to_a
|
71
|
+
end
|
72
|
+
|
73
|
+
alias refresh_events load_events
|
35
74
|
|
36
75
|
private
|
37
76
|
|
77
|
+
def iterate(cron_entries)
|
78
|
+
|
79
|
+
cron_entries.each do |h|
|
80
|
+
|
81
|
+
if h[:cron].to_time.strftime(DF) == Time.now.strftime(DF) then
|
82
|
+
|
83
|
+
Thread.new { run(h[:job]) }
|
84
|
+
h[:cron].next # advances the time
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
38
89
|
def run(job)
|
39
90
|
|
40
91
|
case job
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
y6cNz+NnybgoQfG28NcwV1e/31NTJk5VqdKHKnTfPcp/y35T9YoElNn5cSs93qc5
|
32
32
|
U5VVkvsVQudaZw==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2013-08-
|
34
|
+
date: 2013-08-04 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: dynarex
|
@@ -89,6 +89,20 @@ dependencies:
|
|
89
89
|
- - '>='
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: '0'
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: dynarex-events
|
94
|
+
requirement: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :runtime
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
92
106
|
description:
|
93
107
|
email: james@r0bertson.co.uk
|
94
108
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|