33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/spsclient_m2m.rb', line 33
def run()
log.info 'SPSCLientM2M/run: active' if log
rsc, ste, keywords, reg, reload_keyword = @rsc, @ste, @keywords, @reg,
@reload_keyword
@sps.subscribe(topic: @topic) do |raw_message, topic|
log.info 'SPSCLientM2M/run: received something' if log
if reg and topic == 'system/clock' then
reg.set_key 'hkey_services/spsclient_m2m/last_seen',
"#%s#" % Time.now.to_s
end
if raw_message.strip =~ reload_keyword then
log.info 'SPSClientM2M/run: reloading' if log
ste = SPSTriggerExecute.new keywords, reg=nil, px=nil, log: log
end
if log then
log.info "SPSClientM2M/run: received %s: %s" % [topic, raw_message]
end
a = ste.mae topic: topic, message: raw_message
log.info 'SPSClientM2M/run: a: ' + a.inspect if log
if a.length > 0 then
h = {
rse: ->(x, rsc, params){
job = x.shift[/\/\/job:(.*)/,1]
package_path = x.shift
package = package_path[/([^\/]+)\.rsf$/,1]
if log then
log.info "SPSClientM2M/run: job: %s path: %s package: %s" % \
[job, package_path, package]
end
rsc.run_job package, job, params, args=x, package_path: package_path
},
sps: ->(x, rsc, _){ @sps.notice x },
ste: ->(x, rsc, _){
log.info 'SPSClientM2M/run: before ste run' if log
ste.run x
}
}
end
EM.defer do
a.each do |type, x, params|
Thread.new do
begin
h[type].call x, rsc, params
rescue
err_msg = 'SPSClientM2M/run/error: ' + ($!).inspect
log ? log.debug(err_msg) : puts(err_msg)
end
end
end
end
end
end
|