Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
serradura committed Mar 15, 2024
1 parent cb3d059 commit c11b6ff
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
3 changes: 1 addition & 2 deletions examples/multiple_listeners/db/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
t.string :trace_id, index: true
t.integer :version, null: false
t.integer :duration, null: false, index: true
t.json :ids_tree, null: false, default: []
t.json :ids_matrix, null: false, default: {}
t.json :ids, null: false, default: {}
t.json :records, null: false, default: []

t.timestamps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def on_finish(transitions:)
trace_id: metadata[:trace_id],
version: transitions[:version],
duration: metadata[:duration],
ids_tree: metadata[:ids_tree],
ids_matrix: metadata[:ids_matrix],
ids: metadata[:ids],
records: transitions[:records]
)
rescue ::StandardError => e
Expand Down
2 changes: 1 addition & 1 deletion examples/multiple_listeners/lib/runtime_breaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ module RuntimeBreaker
def self.try_to_interrupt(env:)
return unless String(ENV[env]).strip.start_with?(/1|t/)

raise Interruption, "Runtime breaker activated (#{env})"
raise Interruption, "#{env}"
end
end
12 changes: 8 additions & 4 deletions examples/multiple_listeners/lib/transitions_listener/stdout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def on_record(record:)
end

MapNestedMessages = ->(transitions, buffer, hide_given_and_continue) do
ids_matrix = transitions.dig(:metadata, :ids_matrix)
ids_level_parent = transitions.dig(:metadata, :ids, :level_parent)

messages = buffer.filter_map { |(id, msg)| "#{' ' * ids_matrix[id].last}#{msg}" if ids_matrix[id] }
messages = buffer.filter_map { |(id, msg)| "#{' ' * ids_level_parent[id].first}#{msg}" if ids_level_parent[id] }

messages.reject! { _1.match?(/\(_(given|continue)_\)/) } if hide_given_and_continue

Expand All @@ -47,8 +47,12 @@ def before_interruption(exception:, transitions:)
bc.add_silencer { |line| /lib\/bcdd\/result/.match?(line) }
bc.add_silencer { |line| line.include?(RUBY_VERSION) }

backtrace = bc.clean(exception.backtrace)
dir = "#{FileUtils.pwd[1..]}/"

puts "\nException: #{exception.message} (#{exception.class}); Backtrace: #{backtrace.join(", ")}"
cb = bc.clean(exception.backtrace)
cb.each { _1.sub!(dir, '') }
cb.reject! { _1.match?(/block \(\d levels?\) in|in `block in|internal:kernel/) }

puts "\nException:\n #{exception.message} (#{exception.class})\n\nBacktrace:\n #{cb.join("\n ")}"
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.inherited(subclass)

class << self
def input=(klass)
const_defined?(:Input, false) and raise ArgumentError, 'Attributes class already defined'
const_defined?(:Input, false) and raise ArgumentError, "#{self}::Input class already defined"

unless klass.is_a?(::Class) && klass < Input
raise ArgumentError, 'must be a ApplicationService::Input subclass'
Expand Down
11 changes: 7 additions & 4 deletions examples/single_listener/lib/single_transitions_listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def on_record(record:)
end

MapNestedMessages = ->(transitions, buffer, hide_given_and_continue) do
ids_matrix = transitions.dig(:metadata, :ids_matrix)
ids_level_parent = transitions.dig(:metadata, :ids, :level_parent)

messages = buffer.filter_map { |(id, msg)| "#{' ' * ids_matrix[id].last}#{msg}" if ids_matrix[id] }
messages = buffer.filter_map { |(id, msg)| "#{' ' * ids_level_parent[id].first}#{msg}" if ids_level_parent[id] }

messages.reject! { _1.match?(/\(_(given|continue)_\)/) } if hide_given_and_continue

Expand All @@ -74,8 +74,11 @@ def on_record(record:)
# :metadata => {
# :duration => 0,
# :trace_id => nil,
# :ids_tree => [0, [[1, []], [2, []]]],
# :ids_matrix => {0 => [0, 0], 1 => [1, 1], 2 => [2, 1]}
# :ids => {
# :tree => [0, [[1, []], [2, []]]],
# :matrix => { 0 => [0, 0], 1 => [1, 1], 2 => [2, 1]},
# :level_parent => { 0 => [0, 0], 1 => [1, 0], 2 => [1, 0]}
# }
# },
# :records => [
# # ...
Expand Down

0 comments on commit c11b6ff

Please sign in to comment.