Skip to content

Commit

Permalink
Replace Slack with Rollbar
Browse files Browse the repository at this point in the history
Currently we use a Slack integration to post error messages to Slack. This change replaces that integration with Rollbar.

This change brings this project in line with our standard approach of using Rollbar, and also simplifies the code.
  • Loading branch information
jdudley1123 committed Nov 2, 2023
1 parent e9b2c92 commit f812079
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 42 deletions.
5 changes: 3 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ EMAIL_ALIASES="
[email protected], [email protected]
[email protected], [email protected]
"
SLACK_API_TOKEN=xoxb-PUT-REST-OF-TOKEN-IN
SLACK_NOTIFICATION_CHANNEL="dxw-breathe-productive-sync"

ROLLBAR_ACCESS_TOKEN=
ROLLBAR_ENVIRONMENT= # production | staging | development
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "dotenv"
gem "memo_wise"
gem "productive", "0.6.73"
gem "rake"
gem "rollbar"
gem "slack-ruby-client"

group :development do
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ GEM
request_store (1.5.1)
rack (>= 1.4)
rexml (3.2.6)
rollbar (3.4.1)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
Expand Down Expand Up @@ -155,6 +156,7 @@ DEPENDENCIES
productive (= 0.6.73)
pry
rake
rollbar
rspec
slack-ruby-client
standard
Expand Down
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ synchronising those different systems.
Within dxw this project is deployed and run on Heroku. Due to the sensitive
nature of the data, only a handful of people have access to it.

## Slack Integration

The app will post messages to a slack channel to report if it has encountered
an error. You will need to type `@Breathe Productive Sync` to add them to a new
channel.

You might need to get added to the collaborators list if you need to tweak the
bot's configuration:
https://app.slack.com/app-settings/T025PM7N0/A04U1KEJFKR/collaborators

## Manual usage

Normally you should be running this on a schedule eg on Heroku, but in case you
Expand Down
36 changes: 6 additions & 30 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
require "dotenv"
Dotenv.load

require "slack-ruby-client"

require_relative "lib/event/event"
require_relative "lib/event/event_collection"
require_relative "lib/person/person"
require_relative "lib/breathe_client"
require_relative "lib/productive_client"

Rollbar.configure do |config|
config.access_token = ENV.fetch("ROLLBAR_ACCESS_TOKEN")
config.environment = ENV.fetch("ROLLBAR_ENVIRONMENT")
end

def to_bool(arg)
return true if arg == true || arg =~ (/(true|t|yes|y|1)$/i)
return false if arg == false || arg =~ (/(false|f|no|n|0)$/i)
Expand All @@ -23,26 +26,6 @@ def email_aliases
.map { |line| line.strip.split(/\s*[,;]\s*/) }
end

def configure_slack
Slack.configure do |config|
config.token = ENV.fetch("SLACK_API_TOKEN")
end
Slack::Web::Client.new
end

def notify_slack(client, message)
message_json = message.to_json

client.chat_postMessage(
channel: ENV.fetch("SLACK_NOTIFICATION_CHANNEL"),
text: message,
blocks: %([
{"type": "section", "text": {"type": "mrkdwn", "text": #{message_json}}}
]),
as_user: true
)
end

namespace :productive do
desc "List all event types on Productive"
task :list_event_types do
Expand Down Expand Up @@ -104,14 +87,7 @@ namespace :breathe do

people_to_sync.each { |person| person.sync_breathe_to_productive(after: earliest_date) }
rescue => e
slack_client = configure_slack
message = "There was a *#{e.class}* error with the Breathe/Productive Sync integration:\n" \
"```#{e.message}```\n" \
"Repository: https://github.com/dxw/scheduling-event-sync/"
notify_slack slack_client, message
backtrace = e.backtrace.reject { |x| x.include? "/bundle/ruby/" }
notify_slack slack_client, "Abbreviated stack trace:\n```" + backtrace.join("\n")[0..2975] + "```"
raise
Rollbar.error(e)
end

desc "Obtain the event data from BreatheHR for all or specified employees"
Expand Down

0 comments on commit f812079

Please sign in to comment.