Class: Artery::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/artery/log_subscriber.rb

Instance Method Summary collapse

Instance Method Details

#connection(event) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/artery/log_subscriber.rb', line 40

def connection(event)
  p = event.payload

  case p[:state]
  when :connected    then info "[Backend] connected to #{p[:server]}"
  when :disconnected then warn '[Backend] disconnected'
  when :reconnected  then info "[Backend] reconnected to #{p[:server]}"
  when :closed       then info '[Backend] connection closed'
  end
end

#lock(event) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/artery/log_subscriber.rb', line 60

def lock(event)
  p = event.payload

  case p[:state]
  when :waiting  then debug "[LOCK] waiting (latest_index: #{p[:latest_index]})"
  when :acquired then debug "[LOCK] acquired (latest_index: #{p[:latest_index]}, #{event.duration.round(1)}ms)"
  end
end

#message(event) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/artery/log_subscriber.rb', line 19

def message(event)
  p = event.payload

  case p[:stage]
  when :received then debug "[RECV] <#{p[:route]}> #{truncate_body(p[:data])}"
  when :handled  then debug "[DONE] <#{p[:route]}> (#{event.duration.round(1)}ms)"
  when :skipped  then debug "[SKIP] #{p[:reason]}"
  end
end

#publish(event) ⇒ Object



15
16
17
# File 'lib/artery/log_subscriber.rb', line 15

def publish(event)
  debug "[PUB] <#{event.payload[:route]}> #{truncate_body(event.payload[:data])}"
end

#publisher(event) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/artery/log_subscriber.rb', line 69

def publisher(event)
  p = event.payload

  case p[:action]
  when :started then info 'started'
  when :model_started then info 'polling started'
  when :publishing then debug "published #{p[:count]} messages (#{event.duration.round(1)}ms)"
  when :error then error p[:error]
  end
end

#request(event) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/artery/log_subscriber.rb', line 5

def request(event)
  p = event.payload

  case p[:stage]
  when :sent     then debug "[REQ] <#{p[:route]}> #{truncate_body(p[:data])}"
  when :response then debug "[RESP] <#{p[:route]}> #{truncate_body(p[:data])} (#{p[:duration_ms].round(1)}ms)"
  when :error    then warn "[REQ ERR] <#{p[:route]}> #{p[:error]} (#{p[:duration_ms].round(1)}ms)"
  end
end

#sync(event) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/artery/log_subscriber.rb', line 29

def sync(event)
  p = event.payload

  case p[:stage]
  when :receive_all     then info "[SYNC] receive_all <#{p[:route]}> (#{event.duration.round(1)}ms)"
  when :receive_updates then info "[SYNC] receive_updates <#{p[:route]}> (#{event.duration.round(1)}ms)"
  when :page            then debug "[SYNC] page #{p[:page]} received for <#{p[:route]}>"
  when :continue        then debug '[SYNC] not all updates received, continuing...'
  end
end

#worker(event) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/artery/log_subscriber.rb', line 51

def worker(event)
  p = event.payload

  case p[:action]
  when :started     then info "started (id=#{p[:worker_id]})"
  when :subscribing then debug "[SUB] <#{p[:route]}>"
  end
end