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 7, 2023
1 parent e9b2c92 commit 039748c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 54 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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ gem "dotenv"
gem "memo_wise"
gem "productive", "0.6.73"
gem "rake"
gem "slack-ruby-client"
gem "rollbar"

group :development do
gem "standard"
Expand Down
14 changes: 2 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ GEM
faraday-retry (1.0.3)
faraday_middleware (1.2.0)
faraday (~> 1.0)
gli (2.21.1)
hashie (5.0.0)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
json (2.6.3)
Expand Down Expand Up @@ -80,6 +78,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 @@ -115,12 +114,6 @@ GEM
sawyer (0.9.2)
addressable (>= 2.3.5)
faraday (>= 0.17.3, < 3)
slack-ruby-client (1.0.0)
faraday (>= 1.0)
faraday_middleware
gli
hashie
websocket-driver
standard (1.31.2)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
Expand All @@ -136,9 +129,6 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)

PLATFORMS
arm64-darwin-20
Expand All @@ -155,8 +145,8 @@ DEPENDENCIES
productive (= 0.6.73)
pry
rake
rollbar
rspec
slack-ruby-client
standard

RUBY VERSION
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
35 changes: 6 additions & 29 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,13 +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] + "```"
Rollbar.error(e)
raise
end

Expand Down

0 comments on commit 039748c

Please sign in to comment.