Skip to content
This repository has been archived by the owner on May 22, 2022. It is now read-only.

Commit

Permalink
event-collector: Send timestamps as ms since epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
kemitche committed May 21, 2015
1 parent 868b0f5 commit c216a5f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions r2/r2/lib/eventcollector.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ def _make_http_date(when=None):
return format_date_time(time.mktime(when.timetuple()))


def _epoch_to_millis(timestamp):
"""Convert an epoch_timestamp from seconds (float) to milliseconds (int)"""
return int(timestamp * 1000)


class EventQueue(object):
def __init__(self, queue=r2.lib.amqp):
self.queue = queue
Expand Down Expand Up @@ -76,12 +81,12 @@ def vote_event(self, vote, old_vote=None, event_base=None, request=None,

event_base["event_topic"] = "vote"
event_base["event_name"] = "vote_server"
event_base["event_ts"] = str(epoch_timestamp(vote._date))
event_base["event_ts"] = _epoch_to_millis(epoch_timestamp(vote._date))
event_base["vote_target"] = vote._thing2._fullname
event_base["vote_direction"] = self.VOTES[vote._name]
if old_vote:
event_base["prev_vote_direction"] = self.VOTES[old_vote.direction]
event_base["prev_vote_ts"] = old_vote.date
event_base["prev_vote_ts"] = _epoch_to_millis(old_vote.date)
event_base["vote_type"] = vote._thing2.__class__.__name__.lower()
if event_base["vote_type"] == "link" and vote._thing2.is_self:
event_base["vote_type"] = "self"
Expand All @@ -108,7 +113,9 @@ def submit_event(self, new_link, event_base=None, request=None,

event_base["event_topic"] = "submit"
event_base["event_name"] = "submit_server"
event_base["event_ts"] = str(epoch_timestamp(new_link._date))

submit_ts = epoch_timestamp(new_link._date)
event_base["event_ts"] = _epoch_to_millis(submit_ts)
event_base["id"] = new_link._fullname
event_base["type"] = "self" if new_link.is_self else "link"

Expand Down

0 comments on commit c216a5f

Please sign in to comment.