Module server.stats.event_service
Classes
class EventService (message_queue_service: MessageQueueService)
-
All services should inherit from this class.
Services are singleton objects which manage some server task.
Expand source code
@with_logger class EventService(Service): def __init__(self, message_queue_service: MessageQueueService): self.message_queue_service = message_queue_service async def execute_batch_update(self, player_id, queue): """ Sends a batch of event updates. # Params - `player_id`: the player to update the events for - `queue`: an array of event updates in the form: ``` [{ "eventId": string, "count": long }] ``` # Returns None """ self._logger.info("Recording %d events for player %d", len(queue), player_id) update_data = [ {"playerId": player_id, **data} for data in queue ] await self.message_queue_service.publish_many( config.MQ_EXCHANGE_NAME, "request.event.update", update_data, ) def record_event(self, event_id, count, queue): """ Enqueues an event update. # Params - `event_id`: the event to trigger - `count`: the update count - `queue`: if set, the update will be put into this array for later batch execution """ if count == 0: return queue.append({"eventId": event_id, "count": count})
Ancestors
Methods
async def execute_batch_update(self, player_id, queue)
-
Sends a batch of event updates.
Params
player_id
: the player to update the events forqueue
: an array of event updates in the form:
[{ "eventId": string, "count": long }]
Returns
None
def record_event(self, event_id, count, queue)
-
Enqueues an event update.
Params
event_id
: the event to triggercount
: the update countqueue
: if set, the update will be put into this array for later batch execution
Inherited members