class QueryTrack::Notifications::Slack
Attributes
code[R]
duration[R]
webhook_url[R]
Public Class Methods
new(code, duration)
click to toggle source
# File lib/query_track/notifications/slack.rb, line 6 def initialize(code, duration) @code = code.strip @duration = duration @webhook_url = QueryTrack::Settings.config.notifications.slack end
Public Instance Methods
call()
click to toggle source
# File lib/query_track/notifications/slack.rb, line 12 def call return if webhook_url.nil? || webhook_url.empty? slack_hook = SlackHook::Incoming.new(webhook_url) trace = QueryTrack::Trace.new(caller).call payload = { blocks: blocks(trace) } Thread.new { slack_hook.post(payload) } end
Private Instance Methods
blocks(trace)
click to toggle source
# File lib/query_track/notifications/slack.rb, line 26 def blocks(trace) [ { "type": 'divider' }, { "type": 'section', "text": { "type": 'mrkdwn', "text": "```#{code}```" } }, { "type": 'context', "elements": [ { "type": 'mrkdwn', "text": "Duration: *#{duration}s* " } ] }, { "type": 'context', "elements": [ { "type": 'mrkdwn', "text": "#{trace}" } ] } ] end