Skip to content

Commit

Permalink
More debug logs & set celery worker log level to debug
Browse files Browse the repository at this point in the history
  • Loading branch information
jpopelka committed Oct 9, 2019
1 parent 65360bc commit ccd9b32
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
4 changes: 1 addition & 3 deletions files/run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/bash

export RELEASE_BOT_HOME=/home/release-bot

exec release-bot -c /home/release-bot/.config/conf.yaml &
exec celery -A release_bot.celery_task worker -l info
exec celery -A release_bot.celery_task worker -l debug
20 changes: 14 additions & 6 deletions release_bot/celery_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from release_bot.releasebot import ReleaseBot

DEFAULT_CONF_FILE = "/home/release-bot/.config/conf.yaml"
logger = configuration.logger


@celery_app.task(name="task.celery_task.parse_web_hook_payload")
Expand All @@ -44,7 +45,6 @@ def parse_web_hook_payload(webhook_payload):
installation_id = webhook_payload['installation']['id']
repositories_added = webhook_payload['repositories_added']
save_new_installations(installation_id, repositories_added, db)

if webhook_payload['action'] == 'removed': # detect when repo uninstall app
repositories_removed = webhook_payload['repositories_removed']
delete_installations(repositories_removed, db)
Expand Down Expand Up @@ -88,7 +88,7 @@ def set_configuration(webhook_payload, db, issue=True):
f'{configuration.github_token}@github.com/' \
f'{configuration.repository_owner}/{configuration.repository_name}.git'

return ReleaseBot(configuration), configuration.logger
return ReleaseBot(configuration)


def handle_issue(webhook_payload, db):
Expand All @@ -98,7 +98,7 @@ def handle_issue(webhook_payload, db):
:param db: Redis instance
:return:
"""
release_bot, logger = set_configuration(webhook_payload, db=db, issue=True)
release_bot = set_configuration(webhook_payload, db=db, issue=True)

logger.info("Resolving opened issue")
release_bot.git.pull()
Expand All @@ -122,7 +122,7 @@ def handle_pr(webhook_payload, db):
:param db: Redis instance
:return:
"""
release_bot, logger = set_configuration(webhook_payload, db=db, issue=False)
release_bot = set_configuration(webhook_payload, db=db, issue=False)

logger.info("Resolving opened PR")
release_bot.git.pull()
Expand Down Expand Up @@ -150,11 +150,15 @@ def save_new_installations(installation_id, repositories_added, db):
:param db: Redis instance
:return: True if data was saved successfully into Redis
"""
logger.debug(f"Saving: {installation_id} added to {repositories_added}")
with db.pipeline() as pipe:
for repo in repositories_added:
pipe.set(repo["full_name"], installation_id)
pipe.execute()
return db.save()
success = db.save()
if not success:
logger.error(f"Failed to save {installation_id}:{repositories_added}")
return success


def delete_installations(repositories_removed, db):
Expand All @@ -164,8 +168,12 @@ def delete_installations(repositories_removed, db):
:param db: Redis instance
:return: True if data was deleted successfully into Redis
"""
logger.debug(f"Removing: {repositories_removed}")
with db.pipeline() as pipe:
for repo in repositories_removed:
pipe.delete(repo["full_name"])
pipe.execute()
return db.save()
success = db.save()
if not success:
logger.error(f"Failed to remove {repositories_removed}")
return success
1 change: 1 addition & 0 deletions release_bot/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def load_release_conf(self, conf):
self.logger.warning(msg)
parsed_conf['trigger_on_issue'] = False

self.logger.debug(f"Loaded release-conf.yaml: {parsed_conf}")
return parsed_conf

def set_pypi_project(self, parsed_conf, setup_cfg=None):
Expand Down
4 changes: 2 additions & 2 deletions release_bot/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def __init__(self, conf):
self.logger = conf.logger

def dispatch_request(self):
self.logger.info(f'New github webhook call from detected')
self.logger.info('New github webhook call detected')
if request.is_json:
celery_app.send_task(name="task.celery_task.parse_web_hook_payload",
kwargs={"webhook_payload": request.get_json()})
kwargs={"webhook_payload": request.json})
else:
self.logger.error("This webhook doesn't contain JSON")
return jsonify(result={"status": 200})

0 comments on commit ccd9b32

Please sign in to comment.