Skip to content

Commit

Permalink
Make messages appear in celery logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Houseknecht committed Oct 18, 2016
1 parent 38b7a1b commit f2aae54
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions galaxy/main/celerytasks/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ def refresh_existing_user_repos(token, github_user):
repo_name = repo['name']
repo_owner = repo['owner']['login']
if role.github_repo.lower() != repo_name.lower() or role.github_user.lower() != repo_owner.lower():
logger.info(u'UPDATED: {0} to {1}/{2}'.format(
print u'UPDATED: {0} to {1}/{2}'.format(
full_name,
repo_owner,
repo_name
))
)
role.github_user = repo_owner
role.github_repo = repo_name
role.save()
except UnknownObjectException:
logger.info(u"NOT FOUND: {0}".format(full_name))
print u"NOT FOUND: {0}".format(full_name)
role.delete()
except Exception:
pass
Expand Down Expand Up @@ -251,7 +251,7 @@ def get_readme(import_task, repo, branch, token):
response.raise_for_status()
readme_html = response.text
except Exception as exc:
add_message(import_task, u"ERROR", u"Failed to get HTML version of README: %s" % str(exc))
add_message(import_task, u"ERROR", u"Failed to get HTML version of README: %s" % unicode(exc))

readme = ''
try:
Expand Down Expand Up @@ -279,7 +279,7 @@ def parse_yaml(import_task, file_name, file_contents):
try:
contents = yaml.safe_load(file_contents)
except yaml.YAMLError as exc:
add_message(import_task, u"ERROR", u"YAML parse error: %s" % str(exc))
add_message(import_task, u"ERROR", u"YAML parse error: %s" % unicode(exc))
fail_import_task(import_task, u"Failed to parse %s. Check YAML syntax." % file_name)
return contents

Expand All @@ -293,7 +293,7 @@ def decode_file(import_task, repo, branch, file_name, return_yaml=False):
try:
contents = contents.content.decode('base64')
except Exception as exc:
fail_import_task(import_task, u"Failed to decode %s - %s" % (file_name, str(exc)))
fail_import_task(import_task, u"Failed to decode %s - %s" % (file_name, unicode(exc)))

if not return_yaml:
return contents
Expand Down Expand Up @@ -691,33 +691,33 @@ def import_role(task_id):
@task(name="galaxy.main.celerytasks.tasks.refresh_user_repos", throws=(Exception,))
@transaction.atomic
def refresh_user_repos(user, token):
logger.info(u"Refreshing User Repo Cache for {}".format(user.username).encode('utf-8').strip())
print u"Refreshing User Repo Cache for {}".format(user.username)

try:
gh_api = Github(token)
except GithubException as exc:
user.cache_refreshed = True
user.save()
msg = u"User {0} Repo Cache Refresh Error: {1}".format(user.username, str(exc).encode('utf-8').strip())
logger.error(msg)
msg = u"User {0} Repo Cache Refresh Error: {1}".format(user.username, unicode(exc))
print msg
raise Exception(msg)

try:
ghu = gh_api.get_user()
except GithubException as exc:
user.cache_refreshed = True
user.save()
msg = u"User {0} Repo Cache Refresh Error: {1}".format(user.username, str(exc)).encode('utf-8').strip()
logger.error(msg)
msg = u"User {0} Repo Cache Refresh Error: {1}".format(user.username, unicode(exc))
print msg
raise Exception(msg)

try:
repos = ghu.get_repos()
except GithubException as exc:
user.cache_refreshed = True
user.save()
msg = u"User {0} Repo Cache Refresh Error: {1}".foramt(user.username, str(exc)).encode('utf-8').strip()
logger.error(msg)
msg = u"User {0} Repo Cache Refresh Error: {1}".foramt(user.username, unicode(exc))
print msg
raise Exception(msg)

refresh_existing_user_repos(token, ghu)
Expand All @@ -732,27 +732,27 @@ def refresh_user_repos(user, token):
@task(name="galaxy.main.celerytasks.tasks.refresh_user_stars", throws=(Exception,))
@transaction.atomic
def refresh_user_stars(user, token):
logger.info(u"Refreshing User Stars for {}".format(user.username).encode('utf-8').strip())
print u"Refreshing User Stars for {}".format(user.username)

try:
gh_api = Github(token)
except GithubException as exc:
msg = u"User {0} Refresh Stars: {1}".format(user.username, str(exc)).encode('utf-8').strip()
logger.error(msg)
msg = u"User {0} Refresh Stars: {1}".format(user.username, unicode(exc))
print msg
raise Exception(msg)

try:
ghu = gh_api.get_user()
except GithubException as exc:
msg = u"User {0} Refresh Stars: {1}" % (user.username, str(exc)).encode('utf-8').strip()
logger.error(msg)
msg = u"User {0} Refresh Stars: {1}" % (user.username, unicode(exc))
print msg
raise Exception(msg)

try:
subscriptions = ghu.get_subscriptions()
except GithubException as exc:
msg = u"User {0} Refresh Stars: {1]" % (user.username, str(exc)).encode('utf-8').strip()
logger.error(msg)
msg = u"User {0} Refresh Stars: {1]" % (user.username, unicode(exc))
print msg
raise Exception(msg)

# Refresh user subscriptions class
Expand All @@ -772,8 +772,8 @@ def refresh_user_stars(user, token):
try:
starred = ghu.get_starred()
except GithubException as exc:
msg = u"User {0} Refresh Stars: {1}".format(user.username, str(exc)).encode('utf-8').strip()
logger.error(msg)
msg = u"User {0} Refresh Stars: {1}".format(user.username, unicode(exc))
print msg
raise Exception(msg)

# Refresh user starred cache
Expand Down Expand Up @@ -814,22 +814,22 @@ def refresh_role_counts(start, end, token, tracker):
repo_owner = repo['owner']['login']
if role.github_repo.lower() != repo_name.lower() or role.github_user.lower() != repo_owner.lower():
updated += 1
logger.info(u'UPDATED: {0} to {1}/{2}'.format(
print u'UPDATED: {0} to {1}/{2}'.format(
full_name,
repo_owner,
repo_name
))
)
role.github_user = repo_owner
role.github_repo = repo_name
role.save()
else:
passed += 1
except UnknownObjectException:
logger.info(u"NOT FOUND: {0}".format(full_name))
print u"NOT FOUND: {0}".format(full_name)
role.delete()
deleted += 1
except Exception as exc:
logger.error(u"FAILED: {0} - {1}".format(full_name, unicode(exc)))
print u"FAILED: {0} - {1}".format(full_name, unicode(exc))
failed += 1

tracker.state = 'FINISHED'
Expand All @@ -851,8 +851,7 @@ def clear_stuck_imports():
try:
for ri in ImportTask.objects.filter(created__lte=two_hours_ago, state='PENDING'):
logger.info(u"Clear Stuck Imports: {0} - {1}.{2}"
.format(ri.id, ri.role.namespace, ri.role.name)
.encode('utf-8').strip())
.format(ri.id, ri.role.namespace, ri.role.name))
ri.state = u"FAILED"
ri.messages.create(
message_type=u"ERROR",
Expand All @@ -862,5 +861,5 @@ def clear_stuck_imports():
ri.save()
transaction.commit()
except Exception as exc:
logger.error(u"Clear Stuck Imports ERROR: {}".format(str(exc)).encode('utf-8').strip())
logger.error(u"Clear Stuck Imports ERROR: {}".format(unicode(exc)))
raise

0 comments on commit f2aae54

Please sign in to comment.