Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: webhook self call for Eventarc-triggered events #33

Merged
merged 2 commits into from
Jul 11, 2023

Conversation

nicain
Copy link
Contributor

@nicain nicain commented Jul 11, 2023

Solve retry issue by letting the webhook call itself, and escape any timeout errors so that the original call can still respond to pub/sub (the transport mechanism for the Eventarc call) with a 200 (i.e. request ack and send for processing).

@nicain nicain marked this pull request as ready for review July 11, 2023 16:54
webhook/main.py Outdated
time_created=datetime.datetime.now(datetime.timezone.utc),
event_id="CURL_TRIGGER",
)
if 'bucket' in data:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: get rid of the nested if. Since each branch of the condition returns a value, you can just use the guard pattern:

   if data.get("kind", None) == "storage#object":
        # Entrypoint called by Pub-Sub (Eventarc)
       return redirect_and_reply(data)

   if "bucket" in data:
       return cloud_event_entrypoint(
                name=data["name"],
                event_id=data["id"],
                bucket=data["bucket"],
                time_created=coerce_datetime_zulu(data["timeCreated"]),
            )
   if "text" in data:
       return summarization_entrypoint(
                name=data["name"],
                extracted_text=data["text"],
                time_created=datetime.datetime.now(datetime.timezone.utc),
                event_id="CURL_TRIGGER",
            )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is much cleaner.

@telpirion telpirion changed the title Webhook self call for Eventarc-triggered events feat: webhook self call for Eventarc-triggered events Jul 11, 2023
@nicain nicain force-pushed the self_call_webhook branch from c215a2b to 0fbbaf0 Compare July 11, 2023 17:47
@nicain nicain force-pushed the self_call_webhook branch from 0fbbaf0 to ddde026 Compare July 11, 2023 18:06
@nicain nicain merged commit c86b3d6 into main Jul 11, 2023
@nicain nicain deleted the self_call_webhook branch July 11, 2023 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants