Skip to content

deep.push.push_service

Provide service for pushing events to Deep services.

PushService

This service deals with pushing the snapshots to the service endpoints.

Source code in deep/push/push_service.py
class PushService:
    """This service deals with pushing the snapshots to the service endpoints."""

    def __init__(self, grpc, task_handler):
        """
        Create a service to handle push events.

        :param grpc: the grpc service to use to send events
        :param task_handler: the task handler to offload tasks to
        """
        self.grpc = grpc
        self.task_handler = task_handler

    def push_snapshot(self, snapshot: EventSnapshot):
        """Push a snapshot to the deep services."""
        task = self.task_handler.submit_task(self._push_task, snapshot)
        task.add_done_callback(
            lambda _: logging.debug("Completed uploading snapshot %s", snapshot_id_as_hex_str(snapshot.id)))

    def _push_task(self, snapshot):
        from deep.push import convert_snapshot
        converted = convert_snapshot(snapshot)
        if converted is None:
            return

        logging.debug("Uploading snapshot: %s", snapshot_id_as_hex_str(snapshot.id))

        stub = SnapshotServiceStub(self.grpc.channel)

        stub.send(converted, metadata=self.grpc.metadata())

__init__(grpc, task_handler)

Create a service to handle push events.

:param grpc: the grpc service to use to send events :param task_handler: the task handler to offload tasks to

Source code in deep/push/push_service.py
def __init__(self, grpc, task_handler):
    """
    Create a service to handle push events.

    :param grpc: the grpc service to use to send events
    :param task_handler: the task handler to offload tasks to
    """
    self.grpc = grpc
    self.task_handler = task_handler

push_snapshot(snapshot)

Push a snapshot to the deep services.

Source code in deep/push/push_service.py
def push_snapshot(self, snapshot: EventSnapshot):
    """Push a snapshot to the deep services."""
    task = self.task_handler.submit_task(self._push_task, snapshot)
    task.add_done_callback(
        lambda _: logging.debug("Completed uploading snapshot %s", snapshot_id_as_hex_str(snapshot.id)))