Merge lp:~hloeung/ubuntu-repository-cache/metadata-sync-failure-output-timestamp into lp:ubuntu-repository-cache

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 370
Merged at revision: 370
Proposed branch: lp:~hloeung/ubuntu-repository-cache/metadata-sync-failure-output-timestamp
Merge into: lp:ubuntu-repository-cache
Diff against target: 35 lines (+6/-6)
1 file modified
lib/ubuntu_repository_cache/metadata_sync.py (+6/-6)
To merge this branch: bzr merge lp:~hloeung/ubuntu-repository-cache/metadata-sync-failure-output-timestamp
Reviewer Review Type Date Requested Status
Loïc Gomez +1 Approve
Canonical IS Reviewers Pending
Review via email: mp+428337@code.launchpad.net

Commit message

Add timestamp on output, useful for cron emails

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Loïc Gomez (kotodama) wrote :

+1
You might want to move the formatting to a method if you expect more error logging later

review: Approve (+1)
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 370

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/ubuntu_repository_cache/metadata_sync.py'
2--- lib/ubuntu_repository_cache/metadata_sync.py 2022-08-15 23:25:32 +0000
3+++ lib/ubuntu_repository_cache/metadata_sync.py 2022-08-15 23:49:06 +0000
4@@ -297,7 +297,7 @@
5 label = 'meta_ver={}'.format(meta_ver)
6 failures = 0
7
8- errors = []
9+ errmsgs = []
10 # Work around Juju instability issues causing juju-run to abort
11 # (LP:1977798).
12 max_retries = 10
13@@ -316,18 +316,18 @@
14 msg = "Attempt {} failed, sleeping {} - retrying with {}".format(attempt, sleep, meta_ver)
15 log(msg)
16 log(e.output.decode())
17- errors.append(msg)
18- errors.append(e.output.decode())
19+ errmsgs.append("{}: {}".format(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), msg))
20+ errmsgs.append(e.output.decode())
21 time.sleep(sleep)
22 else:
23 break
24 else:
25 # Exhausted all available attempts, let's re-raise the
26 # exception.
27- msg = "Failed after all available attempts with {}".format(meta_ver)
28+ msg = "Failed after all available attempts ({}) with {}".format(max_retries, meta_ver)
29 log(msg)
30- print(msg)
31- print('\n'.join(errors))
32+ print("{}: {}".format(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), msg))
33+ print('\n'.join(errmsgs))
34 send_to_influx(render_influx(metric_name, label, max_retries))
35 raise exp
36

Subscribers

People subscribed via source and target branches