octue / octue-sdk-python

The python SDK for @Octue services and digital twins.
https://octue.com
Other
10 stars 4 forks source link

Add `octue logs` CLI command #662

Open cortadocodes opened 5 months ago

cortadocodes commented 5 months ago

Feature request

Use Case

I'd like to be able to connect to a question running on a service revision at any given time and see the latest logs stream to me in real time.

Current state

I can use the get_events function and EventReplayer class periodically but this requires repeated manual execution.

Proposed Solution

Add an octue logs CLI command that sets up a subscriber to the events of a question and displays them in real time.

cortadocodes commented 5 months ago

It could looks something like this

from octue.cloud.pub_sub import Subscription, Topic
from octue.resources.service_backends import GCPPubSubBackend
from octue.cloud.pub_sub.service import Service
from octue.cloud.pub_sub.events import GoogleCloudPubSubEventHandler

question_uuid = "facd9ada-f9be-4276-89bb-d114eb6a5302"

topic = Topic(name="octue.services", project_name=PROJECT_NAME)
subscription = Subscription(
    name=f"octue.services.gulfwindtech.dlc-service.add-real-dlc-ser.answers.{question_uuid}",
    topic=topic,
    filter=(
        f'attributes.question_uuid = "{question_uuid}" '
        f'AND attributes.sender_type = "CHILD"'
    ),
)
subscription.create()

event_handler = GoogleCloudPubSubEventHandler(
    subscription=subscription,
    recipient=Service(backend=GCPPubSubBackend(project_name=PROJECT_NAME)),
)

event_handler.handle_events()

subscription.delete()