Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timestamp to single message emails #287

Merged
merged 2 commits into from
Mar 31, 2018

Conversation

mattiaverga
Copy link

Fixes #285
This will add a timestamp as starting line for every single message email.
The other content (message or dump) remains unchanged.

@codecov
Copy link

codecov bot commented Mar 27, 2018

Codecov Report

Merging #287 into develop will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #287      +/-   ##
===========================================
+ Coverage    56.92%   56.95%   +0.03%     
===========================================
  Files           70       70              
  Lines         3719     3722       +3     
  Branches       477      477              
===========================================
+ Hits          2117     2120       +3     
  Misses        1536     1536              
  Partials        66       66
Impacted Files Coverage Δ
fmn/formatters.py 82.01% <100%> (+0.19%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1d9d28f...7e10dff. Read the comment docs.

Copy link
Member

@jeremycline jeremycline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for handling this, there's just one tweak needed to avoid confusion down the road

@@ -399,11 +399,13 @@ def email(message, recipient):
subject_prefix.strip(), subject.strip())
email_message.add_header('Subject', subject.encode('utf-8'))

timestamp = datetime.datetime.fromtimestamp(message['timestamp'])
content = timestamp.strftime('%c') + u'\n'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not documented anywhere AFAIK, but those timestamps are UTC so we should note that to avoid confusion. Maybe something like:

import pytz
utc_timestamp = pytz.utc.localize(message['timestamp']).strftime('%Y-%m-%d %H:%M:%S %Z')
content = u'Notification time stamped {}\n\n'.format(utc_timestamp)

Sorry, I know this is going to make you edit all those test results again :( - I should have been less lazy and added something to encode the expected results with base64 automatically.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make more sense if the timezone is already set in the received message['timestamp'] (is that from fedmsg?).
Maybe we can ask fedmsg to implement that, in the meantime I can just modify here to set the timezone if the received message['timestamp'] is not already timezone aware.

And I think I should also modify the timestamps in digest creation in the same way.
What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make more sense if the timezone is already set in the received message['timestamp'] (is that from fedmsg?) Maybe we can ask fedmsg to implement that, in the meantime I can just modify here to set the timezone if the received message['timestamp'] is not already timezone aware.

So looking at the fedmsg source, it's just time.time() which is seconds since the epoch (January 1, 1970, 00:00:00 (UTC)): https://github.com/fedora-infra/fedmsg/blob/a0547bb08372ade44adb088bc57de34f0f86e729/fedmsg/core.py#L290. This makes it easy for consumers to convert it to whatever timezone they desire, so I think it's best to leave that as it is.

I did realize my suggestion is wrong, though, since pytz.utc.localize wants datetime objects. An easier implementation is just datetime.datetime.fromtimestamp(message['timestamp'], tz=pytz.utc).

And I think I should also modify the timestamps in digest creation in the same way.
What do you think?

Yes, that's a good idea - you should just need to add that tz kwarg.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was confusing timestamps with datetime objects too... :-(
I'll work on it in the next days as soon as I have some free time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks!

@mattiaverga
Copy link
Author

It seems that the failure is not due to the PR, but to an internal error of Travis, doesn't it?

@jeremycline jeremycline merged commit ce97e44 into fedora-infra:develop Mar 31, 2018
@jeremycline
Copy link
Member

Yeah, Travis is occasionally flaky. What I tend to do is just git commit --amend and force push to retrigger the tests. Thanks for this!

@mattiaverga mattiaverga deleted the msg_timestamp branch April 1, 2018 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants