| |
@@ -24,16 +24,21 @@
|
| |
|
| |
import logging
|
| |
import warnings
|
| |
+ import traceback
|
| |
|
| |
import fedmsg
|
| |
import fedmsg.config
|
| |
+ import jinja2
|
| |
+ import jira
|
| |
|
| |
import sync2jira.upstream as u
|
| |
import sync2jira.downstream as d
|
| |
+ from sync2jira.mailer import send_mail
|
| |
|
| |
|
| |
log = logging.getLogger('sync2jira.main')
|
| |
remote_link_title = "Upstream issue"
|
| |
+ failure_email_subject = "Sync2Jira Has Failed!"
|
| |
|
| |
handlers = {
|
| |
# Example: https://apps.fedoraproject.org/datagrepper/id?id=2016-895ed21e-5d53-4fde-86ac-64dab36a14ad&is_raw=true&size=extra-large
|
| |
@@ -184,13 +189,42 @@
|
| |
logging.basicConfig(level=logging.INFO)
|
| |
warnings.simplefilter("ignore")
|
| |
|
| |
- if config['sync2jira'].get('initialize'):
|
| |
- initialize(config)
|
| |
-
|
| |
try:
|
| |
- listen(config)
|
| |
- except KeyboardInterrupt:
|
| |
- pass
|
| |
+ if config['sync2jira'].get('initialize'):
|
| |
+ initialize(config)
|
| |
+
|
| |
+ try:
|
| |
+ listen(config)
|
| |
+ except KeyboardInterrupt:
|
| |
+ pass
|
| |
+ except:
|
| |
+ report_failure(config)
|
| |
+ raise
|
| |
+
|
| |
+
|
| |
+ def report_failure(config):
|
| |
+ """
|
| |
+ Helper function to alert admins in case of failure.
|
| |
+
|
| |
+
|
| |
+ :param Dict config: Config dict for JIRA
|
| |
+ """
|
| |
+ # Email our admins with the traceback
|
| |
+ templateLoader = jinja2.FileSystemLoader(searchpath='sync2jira/')
|
| |
+ templateEnv = jinja2.Environment(loader=templateLoader)
|
| |
+ template = templateEnv.get_template('failure_template.jinja')
|
| |
+ html_text = template.render(traceback=traceback.format_exc())
|
| |
+
|
| |
+ # Get admin information
|
| |
+ admins = []
|
| |
+ for admin in config['sync2jira']['admins']:
|
| |
+ admins.append(admin.values()[0])
|
| |
+
|
| |
+ # Send mail
|
| |
+ send_mail(recipients=admins,
|
| |
+ cc=None,
|
| |
+ subject=failure_email_subject,
|
| |
+ text=html_text)
|
| |
|
| |
|
| |
def list_managed():
|
| |
If Syns2Jira fails, who gets alerted. This PR aims to fix that by looking up the admins (through the default JIRA instance) and sends them an email with the full traceback when Sync2Jira fails!