marty 1.0.17 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/models/marty/event.rb +68 -5
- data/lib/marty/promise_job.rb +19 -12
- data/lib/marty/version.rb +1 -1
- data/spec/models/event_spec.rb +69 -51
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ace581b64a26ea52006a992b316d6fcbc116182a
|
4
|
+
data.tar.gz: 3b011c6884664a254934baed99a2ef959381fb79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 717f673b5b71f9d4b0e1c5605cdf84e6ecb4c1e06cf508f495ea642f55c96f5edef84f13cbb79cb490cb5329856cbc0b36a344e83f993eba1ffac741a3d13a70
|
7
|
+
data.tar.gz: 1d49e5c28c8783ed3bbae741d9701b74f3ef75389f8c6c1dd0ccc59f343cfab061f3b649834fd90587273853356fd3f4c67052704e63bbdeb98193afa413bc41
|
data/app/models/marty/event.rb
CHANGED
@@ -88,6 +88,7 @@ SQL
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def self.lookup_event(klass, subject_id, operation)
|
91
|
+
update_start_and_end
|
91
92
|
get_data("#{BASE_QUERY}
|
92
93
|
WHERE klass = '#{klass}'
|
93
94
|
AND subject_id = #{subject_id}
|
@@ -133,12 +134,72 @@ SQL
|
|
133
134
|
ORDER BY end_dt desc").first
|
134
135
|
end
|
135
136
|
|
137
|
+
def self.last_event_multi(klass, subject_ids_arg, operation=nil)
|
138
|
+
subject_ids = subject_ids_arg.map(&:to_i)
|
139
|
+
events = all_running.select do |pm|
|
140
|
+
pm["klass"] == klass && subject_ids.include?(pm["subject_id"]) &&
|
141
|
+
(operation.nil? || pm["enum_event_operation"] == operation)
|
142
|
+
end.group_by { |ev| ev["subject_id"] }.each_with_object({}) do
|
143
|
+
|(id, evs), h|
|
144
|
+
h[id] = evs.sort { |a, b| a["start_dt"] <=> b["start_dt"] }.first
|
145
|
+
end
|
146
|
+
|
147
|
+
running_ids = events.keys
|
148
|
+
check_fin = subject_ids - running_ids
|
149
|
+
|
150
|
+
if check_fin.present?
|
151
|
+
op_filt = "AND enum_event_operation = '#{operation}'" if operation
|
152
|
+
op_col = ", enum_event_operation" if operation
|
153
|
+
|
154
|
+
fins = get_data("SELECT klass,
|
155
|
+
subject_id,
|
156
|
+
enum_event_operation,
|
157
|
+
comment,
|
158
|
+
start_dt,
|
159
|
+
end_dt,
|
160
|
+
expire_secs,
|
161
|
+
error
|
162
|
+
FROM (SELECT klass,
|
163
|
+
subject_id,
|
164
|
+
enum_event_operation,
|
165
|
+
comment,
|
166
|
+
start_dt,
|
167
|
+
end_dt,
|
168
|
+
expire_secs,
|
169
|
+
error,
|
170
|
+
ROW_NUMBER() OVER (PARTITION BY klass,
|
171
|
+
subject_id
|
172
|
+
#{op_col}
|
173
|
+
ORDER BY end_dt DESC) rnum
|
174
|
+
FROM marty_events
|
175
|
+
WHERE klass = '#{klass}'
|
176
|
+
AND subject_id IN (#{check_fin.join(',')})
|
177
|
+
#{op_filt}
|
178
|
+
AND end_dt IS NOT NULL) sub
|
179
|
+
WHERE rnum = 1")
|
180
|
+
|
181
|
+
fins.each do |fin|
|
182
|
+
events[fin["subject_id"]] = fin
|
183
|
+
end
|
184
|
+
end
|
185
|
+
events
|
186
|
+
end
|
187
|
+
|
136
188
|
def self.currently_running(klass, subject_id)
|
137
189
|
all_running.select do |pm|
|
138
190
|
pm["klass"] == klass && pm["subject_id"] == subject_id.to_i
|
139
191
|
end.map { |e| e["enum_event_operation"] }
|
140
192
|
end
|
141
193
|
|
194
|
+
def self.currently_running_multi(klass, subject_id_raw)
|
195
|
+
subject_ids = [subject_id_raw].flatten.map(&:to_i)
|
196
|
+
all_running.select do |pm|
|
197
|
+
pm["klass"] == klass && subject_ids.include?(pm["subject_id"])
|
198
|
+
end.each_with_object({}) do |e, h|
|
199
|
+
(h[e["subject_id"]] ||= []) << e["enum_event_operation"]
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
142
203
|
def self.update_comment(hash, comment)
|
143
204
|
hid = hash.is_a?(Hash) ? hash['id'] : hash
|
144
205
|
e = Marty::Event.find_by_id(hid)
|
@@ -158,7 +219,7 @@ SQL
|
|
158
219
|
end
|
159
220
|
|
160
221
|
def self.update_start_and_end
|
161
|
-
ActiveRecord::Base.connection.execute(UPDATE_SQL)
|
222
|
+
ActiveRecord::Base.connection.execute(UPDATE_SQL).cmd_tuples
|
162
223
|
end
|
163
224
|
|
164
225
|
def self.get_data(sql)
|
@@ -185,8 +246,9 @@ SQL
|
|
185
246
|
time_now = Time.zone.now
|
186
247
|
time_now_i = time_now.to_i
|
187
248
|
time_now_s = time_now.strftime('%Y-%m-%d %H:%M:%S.%6N')
|
188
|
-
|
189
|
-
|
249
|
+
upd_count = update_start_and_end
|
250
|
+
if upd_count > 0 ||
|
251
|
+
time_now_i - @all_running[:timestamp] > @poll_secs
|
190
252
|
@all_running[:data] = get_data(running_query(time_now_s))
|
191
253
|
@all_running[:timestamp] = time_now_i
|
192
254
|
end
|
@@ -204,8 +266,9 @@ SQL
|
|
204
266
|
cutoff = Time.zone.at(@all_finished[:timestamp]).
|
205
267
|
strftime('%Y-%m-%d %H:%M:%S.%6N')
|
206
268
|
|
207
|
-
|
208
|
-
|
269
|
+
upd_count = update_start_and_end
|
270
|
+
if upd_count > 0 ||
|
271
|
+
time_now_i - @all_finished[:timestamp] > @poll_secs
|
209
272
|
raw = get_data(
|
210
273
|
"SELECT * FROM
|
211
274
|
(SELECT ROW_NUMBER() OVER (PARTITION BY klass,
|
data/lib/marty/promise_job.rb
CHANGED
@@ -58,13 +58,21 @@ class Delorean::BaseModule::NodeCall
|
|
58
58
|
promise.job_id = job.id
|
59
59
|
promise.save!
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
61
|
+
evh = params["p_event"]
|
62
|
+
if evh
|
63
|
+
event, klass, subject_id, operation = evh.values_at("event", "klass",
|
64
|
+
"id", "operation")
|
65
|
+
if event
|
66
|
+
event.promise_id = promise.id
|
67
|
+
event.save!
|
68
|
+
else
|
69
|
+
event = Marty::Event.
|
70
|
+
create!(promise_id: promise.id,
|
71
|
+
klass: klass,
|
72
|
+
subject_id: subject_id,
|
73
|
+
enum_event_operation: operation)
|
74
|
+
end
|
75
|
+
end
|
68
76
|
Marty::PromiseProxy.new(promise.id, timeout, attr)
|
69
77
|
end
|
70
78
|
end
|
@@ -106,11 +114,10 @@ class Marty::PromiseJob < Struct.new(:promise,
|
|
106
114
|
|
107
115
|
engine = Marty::ScriptSet.new(tag).get_engine(sname)
|
108
116
|
|
109
|
-
engine.evaluate_attrs(node, attrs, params)
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
}
|
117
|
+
attrs_eval = engine.evaluate_attrs(node, attrs, params)
|
118
|
+
res = attrs.zip(attrs_eval).each_with_object({}) do |(attr, val), h|
|
119
|
+
h[attr] = val
|
120
|
+
end
|
114
121
|
|
115
122
|
# log "DONE #{Process.pid} #{promise.id} #{Time.now.to_f} #{res}"
|
116
123
|
rescue => exc
|
data/lib/marty/version.rb
CHANGED
data/spec/models/event_spec.rb
CHANGED
@@ -29,6 +29,8 @@ describe Marty::Event do
|
|
29
29
|
nil],
|
30
30
|
['testcl1', 123, @time + 4.seconds, nil,10000, 'PRICING', 'c comment',
|
31
31
|
nil],
|
32
|
+
['testcl1', 234, @time - 5.seconds, @time, nil, 'PRICING', 'c comment',
|
33
|
+
false],
|
32
34
|
['testcl2', 123, @time, nil, 2, 'AVM', 'e comment', nil],
|
33
35
|
['testcl2', 123, @time + 1.second, nil, 4, 'CRA', 'f comment', nil],
|
34
36
|
['testcl2', 123, Time.zone.parse(@old_start),
|
@@ -36,27 +38,27 @@ describe Marty::Event do
|
|
36
38
|
].each do
|
37
39
|
|klass, subjid, startdt, enddt, expire, op, comment, error|
|
38
40
|
Marty::Event.create!(klass: klass,
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
subject_id: subjid,
|
42
|
+
start_dt: startdt,
|
43
|
+
end_dt: enddt,
|
44
|
+
expire_secs: expire,
|
45
|
+
comment: comment,
|
46
|
+
enum_event_operation: op,
|
47
|
+
error: error)
|
46
48
|
end
|
47
49
|
|
48
50
|
|
49
51
|
engine = Marty::ScriptSet.new.get_engine(NAME_I)
|
50
52
|
res = engine.background_eval("SLEEPER", {"secs" => 5}, ["a"],
|
51
|
-
|
52
|
-
|
53
|
-
|
53
|
+
{klass: "testcl3",
|
54
|
+
id: 987,
|
55
|
+
operation: 'PRICING'})
|
54
56
|
res.force
|
55
57
|
engine = Marty::ScriptSet.new.get_engine(NAME_J)
|
56
58
|
res = engine.background_eval("FAILER", {"dummy" => "dummy"}, ["a"],
|
57
|
-
|
58
|
-
|
59
|
-
|
59
|
+
{klass: "testcl3",
|
60
|
+
id: 654,
|
61
|
+
operation: 'PRICING'})
|
60
62
|
res.force rescue nil
|
61
63
|
sleep 5
|
62
64
|
save_clean_db(@save_file)
|
@@ -75,46 +77,46 @@ describe Marty::Event do
|
|
75
77
|
|
76
78
|
|
77
79
|
it "reports currently running" do
|
78
|
-
expect(Marty::Event.currently_running('testcl1', 123)).
|
79
|
-
['AVM', 'CRA', 'PRICING'])
|
80
|
+
expect(Marty::Event.currently_running('testcl1', 123)).
|
81
|
+
to eq(['AVM', 'CRA', 'PRICING'])
|
80
82
|
expect(Marty::Event.currently_running('testcl2', 123)).to eq([])
|
81
83
|
expect(Marty::Event.currently_running('testcl3', 987)).to eq([])
|
82
|
-
expect(Marty::Event.last_event('testcl1', 123)).
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
84
|
+
expect(Marty::Event.last_event('testcl1', 123)).
|
85
|
+
to include(
|
86
|
+
{"klass"=>"testcl1",
|
87
|
+
"subject_id"=>123,
|
88
|
+
"enum_event_operation"=>"PRICING",
|
89
|
+
"comment"=>"c comment", "expire_secs"=>10000})
|
90
|
+
expect(Marty::Event.last_event('testcl2', 123)).
|
91
|
+
to include(
|
92
|
+
{"klass"=>"testcl2",
|
93
|
+
"subject_id"=>123,
|
94
|
+
"enum_event_operation"=>"PRICING",
|
95
|
+
"comment"=>"old event"})
|
96
|
+
expect(Marty::Event.last_event('testcl3', 987)).
|
97
|
+
to include(
|
98
|
+
{"klass"=>"testcl3",
|
99
|
+
"subject_id"=>987,
|
100
|
+
"enum_event_operation"=>"PRICING",
|
101
|
+
"comment"=>nil,
|
102
|
+
"expire_secs"=>nil})
|
98
103
|
|
99
104
|
Timecop.freeze(@time+1.second)
|
100
105
|
Marty::Event.clear_cache
|
101
|
-
expect(Marty::Event.currently_running('testcl1', 123)).
|
102
|
-
['AVM', 'CRA', 'PRICING'])
|
103
|
-
expect(Marty::Event.currently_running('testcl2', 123)).to eq(
|
104
|
-
['AVM', 'CRA'])
|
106
|
+
expect(Marty::Event.currently_running('testcl1', 123)).
|
107
|
+
to eq(['AVM', 'CRA', 'PRICING'])
|
108
|
+
expect(Marty::Event.currently_running('testcl2', 123)).to eq(['AVM', 'CRA'])
|
105
109
|
|
106
110
|
Timecop.freeze(@time+3.seconds)
|
107
111
|
Marty::Event.clear_cache
|
108
|
-
expect(Marty::Event.currently_running('testcl1', 123)).
|
109
|
-
['AVM', 'CRA', 'PRICING'])
|
110
|
-
expect(Marty::Event.currently_running('testcl2', 123)).to eq(
|
111
|
-
['CRA'])
|
112
|
+
expect(Marty::Event.currently_running('testcl1', 123)).
|
113
|
+
to eq(['AVM', 'CRA', 'PRICING'])
|
114
|
+
expect(Marty::Event.currently_running('testcl2', 123)).to eq(['CRA'])
|
112
115
|
|
113
116
|
Timecop.freeze(@time+6.seconds)
|
114
|
-
expect(Marty::Event.currently_running('testcl1', 123)).
|
115
|
-
['AVM', 'CRA', 'PRICING'])
|
116
|
-
expect(Marty::Event.currently_running('testcl2', 123)).to eq(
|
117
|
-
[])
|
117
|
+
expect(Marty::Event.currently_running('testcl1', 123)).
|
118
|
+
to eq(['AVM', 'CRA', 'PRICING'])
|
119
|
+
expect(Marty::Event.currently_running('testcl2', 123)).to eq([])
|
118
120
|
Timecop.return
|
119
121
|
|
120
122
|
end
|
@@ -142,7 +144,7 @@ describe Marty::Event do
|
|
142
144
|
expect(ev4.end_dt).not_to be_nil
|
143
145
|
expect(ev4.error).to be_truthy
|
144
146
|
|
145
|
-
expect(af.count).to eq(
|
147
|
+
expect(af.count).to eq(4)
|
146
148
|
expect(af).to include(['testcl3', 987])
|
147
149
|
expect(af).to include(['testcl2', 123])
|
148
150
|
expect(af[['testcl3', 987]]).to include('PRICING')
|
@@ -150,13 +152,16 @@ describe Marty::Event do
|
|
150
152
|
expect(af[['testcl2', 123]]).to include('PRICING')
|
151
153
|
expect(af[['testcl2', 123]]['PRICING']).to eq(@old_end)
|
152
154
|
|
153
|
-
expect(Marty::Event.currently_running('testcl1', 123)).
|
154
|
-
['AVM', 'CRA', 'PRICING'])
|
155
|
+
expect(Marty::Event.currently_running('testcl1', 123)).
|
156
|
+
to eq(['AVM', 'CRA', 'PRICING'])
|
155
157
|
expect(Marty::Event.op_is_running?('testcl1', 123, 'AVM')).to be_truthy
|
156
158
|
Marty::Event.finish_event('testcl1', 123, 'AVM', false, 'wassup')
|
157
159
|
Marty::Event.clear_cache
|
158
|
-
expect(Marty::Event.currently_running('testcl1', 123)).
|
159
|
-
['CRA', 'PRICING'])
|
160
|
+
expect(Marty::Event.currently_running('testcl1', 123)).
|
161
|
+
to eq(['CRA', 'PRICING'])
|
162
|
+
expect(Marty::Event.currently_running_multi('testcl1', [123])).
|
163
|
+
to eq({123 => ['CRA', 'PRICING']})
|
164
|
+
|
160
165
|
expect(Marty::Event.op_is_running?('testcl1', 123, 'AVM')).to be_falsey
|
161
166
|
expect(Marty::Event.op_is_running?('testcl1', 123, 'CRA')).to be_truthy
|
162
167
|
|
@@ -175,9 +180,22 @@ describe Marty::Event do
|
|
175
180
|
expect(Marty::Event.pretty_op(ev.first)).to eq('Avm')
|
176
181
|
ev = Marty::Event.lookup_event('testcl1', 123, 'PRICING').first
|
177
182
|
expect(Marty::Event.pretty_op(ev)).to eq('Pricing')
|
183
|
+
evs = Marty::Event.last_event_multi('testcl1', [123, 234])
|
184
|
+
expect(evs[123]).to include({"klass"=>"testcl1",
|
185
|
+
"subject_id"=>123,
|
186
|
+
"enum_event_operation"=>"CRA",
|
187
|
+
"comment"=>"b comment",
|
188
|
+
"expire_secs"=>nil,
|
189
|
+
"error"=>nil})
|
190
|
+
expect(evs[234]).to include({"klass"=>"testcl1",
|
191
|
+
"subject_id"=>234,
|
192
|
+
"enum_event_operation"=>"PRICING",
|
193
|
+
"comment"=>"c comment",
|
194
|
+
"expire_secs"=>nil,
|
195
|
+
"error"=>"f"})
|
178
196
|
|
179
197
|
af = Marty::Event.all_finished
|
180
|
-
expect(af.count).to eq(
|
198
|
+
expect(af.count).to eq(5)
|
181
199
|
expect(af[['testcl3', 987]]).to include('PRICING')
|
182
200
|
expect(af[['testcl1', 123]]).to include('AVM')
|
183
201
|
expect(af[['testcl1', 123]]['AVM']).to start_with(@date_string)
|
@@ -191,7 +209,7 @@ describe Marty::Event do
|
|
191
209
|
"the comment") }.
|
192
210
|
to raise_error(%r!AVM is already running for testcl/1234!)
|
193
211
|
expect {Marty::Event.create_event('testcl', 2345, 'AVM', Time.zone.now, 600,
|
194
|
-
|
212
|
+
"the comment") }.not_to raise_error
|
195
213
|
expect {Marty::Event.finish_event('testcl', 1234, 'AVM', false,
|
196
214
|
"new comment") }.
|
197
215
|
not_to raise_error
|
@@ -209,7 +227,7 @@ describe Marty::Event do
|
|
209
227
|
to raise_error(%r!PG::.*invalid input value for enum.*"AMV"!)
|
210
228
|
Marty::Event.clear_cache
|
211
229
|
af = Marty::Event.all_finished
|
212
|
-
expect(af.count).to eq(
|
230
|
+
expect(af.count).to eq(6)
|
213
231
|
expect(af).to include(['testcl', 1234])
|
214
232
|
expect(af).to include(['testcl', 2345])
|
215
233
|
expect(af[['testcl', 1234]]).to include('AVM')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arman Bostani
|
@@ -14,7 +14,7 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date:
|
17
|
+
date: 2017-01-10 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: pg
|