From 68aaf9cd61e17a60ab15e46bf1fc929dfa3d8a9f Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 8 Oct 2018 13:30:00 +0000 Subject: [PATCH] Message timestamp refactored --- platypush/message/__init__.py | 3 +++ platypush/message/event/__init__.py | 2 +- platypush/message/request/__init__.py | 3 ++- platypush/message/response/__init__.py | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/platypush/message/__init__.py b/platypush/message/__init__.py index 122f03eb..a5561229 100644 --- a/platypush/message/__init__.py +++ b/platypush/message/__init__.py @@ -9,6 +9,9 @@ logger = logging.getLogger(__name__) class Message(object): """ Message generic class """ + def __init__(self, timestamp=None, *args, **kwargs): + self.timestamp = timestamp or time.time() + def __str__(self): """ Overrides the str() operator and converts diff --git a/platypush/message/event/__init__.py b/platypush/message/event/__init__.py index 2a7f7df7..6d70826b 100644 --- a/platypush/message/event/__init__.py +++ b/platypush/message/event/__init__.py @@ -23,13 +23,13 @@ class Event(Message): kwargs -- Additional arguments for the event [kwDict] """ + super().__init__(timestamp=timestamp) self.id = id if id else self._generate_id() self.target = target if target else Config.get('device_id') self.origin = origin if origin else Config.get('device_id') self.type = '{}.{}'.format(self.__class__.__module__, self.__class__.__name__) self.args = kwargs - self.timestamp = timestamp or time.time() @classmethod def build(cls, msg): diff --git a/platypush/message/request/__init__.py b/platypush/message/request/__init__.py index 63c250b1..04659b36 100644 --- a/platypush/message/request/__init__.py +++ b/platypush/message/request/__init__.py @@ -35,6 +35,8 @@ class Request(Message): timestamp -- Message creation timestamp [Float] """ + super().__init__(timestamp=timestamp) + self.id = id if id else self._generate_id() self.target = target self.action = action @@ -42,7 +44,6 @@ class Request(Message): self.args = args if args else {} self.backend = backend self.token = token - self.timestamp = timestamp or time.time() @classmethod def build(cls, msg): diff --git a/platypush/message/response/__init__.py b/platypush/message/response/__init__.py index b7e03ae8..530bf469 100644 --- a/platypush/message/response/__init__.py +++ b/platypush/message/response/__init__.py @@ -18,11 +18,11 @@ class Response(Message): timestamp -- Message timestamp [Float] """ + super().__init__(timestamp=timestamp) self.target = target self.output = self._parse_msg(output) self.errors = self._parse_msg(errors) self.origin = origin - self.timestamp = timestamp or time.time() self.id = id def is_error(self):