Skip to content

Commit

Permalink
Add Sentry exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
h3h committed Jun 26, 2017
1 parent cfc2d27 commit 46bfc6b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -74,3 +74,12 @@ To minimize the risk of making a mistake, Destalinator will run in a dry-run mod
#### `DESTALINATOR_LOG_LEVEL`

Tune your preferred log level for server logs or local debugging. Does not affect the ENV var specified by `output_debug_env_varname`.

#### `SENTRY_DSN`

In order to configure exception handling & tracking with [Sentry](https://sentry.io/), set up a Sentry account and
configure this environment variable with the appropriate DSN value.

If you're on Heroku, you can provision this with:

heroku addons:create sentry:f1
1 change: 1 addition & 0 deletions requirements.txt
@@ -1,3 +1,4 @@
APScheduler==3.0.5
requests==2.9.1
PyYAML==3.11
raven==6.1.0
41 changes: 26 additions & 15 deletions scheduler.py
@@ -1,10 +1,16 @@
from apscheduler.schedulers.blocking import BlockingScheduler
import logging
import os

from apscheduler.schedulers.blocking import BlockingScheduler
from raven.base import Client as RavenClient

import warner
import archiver
import announcer
import flagger
import os


raven_client = RavenClient()


# When testing changes, set the "TEST_SCHEDULE" envvar to run more often
Expand All @@ -16,25 +22,30 @@
logging.basicConfig()
sched = BlockingScheduler()


@sched.scheduled_job("cron", **schedule_kwargs)
def destalinate_job():
print("Destalinating")
if "SB_TOKEN" not in os.environ or "API_TOKEN" not in os.environ:
print("ERR: Missing at least one Slack environment variable.")
else:
scheduled_warner = warner.Warner()
scheduled_archiver = archiver.Archiver()
scheduled_announcer = announcer.Announcer()
scheduled_flagger = flagger.Flagger()
print("Warning")
scheduled_warner.warn()
print("Archiving")
scheduled_archiver.archive()
print("Announcing")
scheduled_announcer.announce()
print("Flagging")
scheduled_flagger.flag()
print("OK: destalinated")
try:
scheduled_warner = warner.Warner()
scheduled_archiver = archiver.Archiver()
scheduled_announcer = announcer.Announcer()
scheduled_flagger = flagger.Flagger()
print("Warning")
scheduled_warner.warn()
print("Archiving")
scheduled_archiver.archive()
print("Announcing")
scheduled_announcer.announce()
print("Flagging")
scheduled_flagger.flag()
print("OK: destalinated")
except Exception: # pylint: disable=W0703
raven_client.captureException()
print("END: destalinate_job")


sched.start()

0 comments on commit 46bfc6b

Please sign in to comment.