From 68b93f0ea4e373a571197f7b6734ab70a260d347 Mon Sep 17 00:00:00 2001 From: "joseph@dxw.com" Date: Thu, 2 Nov 2023 17:02:48 +0000 Subject: [PATCH] Replace Slack with Rollbar 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. --- .env.example | 5 +++-- Gemfile | 2 +- Gemfile.lock | 2 ++ README.md | 10 ---------- Rakefile | 35 ++++++----------------------------- 5 files changed, 12 insertions(+), 42 deletions(-) diff --git a/.env.example b/.env.example index 02b410e..3f46036 100644 --- a/.env.example +++ b/.env.example @@ -23,5 +23,6 @@ EMAIL_ALIASES=" person@dxw.com, nickname@dxw.com other-person@dxw.com, other-nickname@dxw.com " -SLACK_API_TOKEN=xoxb-PUT-REST-OF-TOKEN-IN -SLACK_NOTIFICATION_CHANNEL="dxw-breathe-productive-sync" + +ROLLBAR_ACCESS_TOKEN= +ROLLBAR_ENVIRONMENT= # production | staging | development diff --git a/Gemfile b/Gemfile index e091d5c..1621d4d 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/Gemfile.lock b/Gemfile.lock index 6205976..811f94c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -155,6 +156,7 @@ DEPENDENCIES productive (= 0.6.73) pry rake + rollbar rspec slack-ruby-client standard diff --git a/README.md b/README.md index 0eace7d..ae94371 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Rakefile b/Rakefile index d768010..6d1341d 100644 --- a/Rakefile +++ b/Rakefile @@ -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) @@ -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 @@ -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