6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'app/services/import_events.rb', line 6
def self.call
redis = Redis.new(url: 'redis://localhost:6379')
begin
redis.subscribe('events') do |on|
on.message do |channel, message|
puts "Received message on channel #{channel}: #{message}"
event = Hashie::Mash.new(JSON.parse(message))
run = Hyperlayer::Run.where(process: event.spec.process).first_or_create
path = Hyperlayer::Path.where(path: event.path).first_or_create
spec_file = event.spec.tree.reverse.first
spec = run.specs.where(
location: spec_file.file_path,
description: spec_file.description, data: spec_file.except(:file_path, :description)
).first_or_create
example_groups = event.spec.tree.reverse[1..]
groups = example_groups.map do |example_group|
spec.example_groups.where(
location: example_group.location,
description: example_group.description,
data: example_group.except(:location, :description)
).first_or_create
end
example_group = groups.last
example_group.events.create(
path: path,
line_number: event.line_number,
defined_class: event.defined_class,
event_type: event.event,
method: event.method_id,
return_value: event.return_value,
arguments: event.arguments,
variables: event.variables
)
end
end
rescue Redis::BaseConnectionError => error
puts "#{error}, retrying in 1s"
sleep 1
retry
end
end
|