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

Task to Trigger Google Cloud Function #4836

Closed
marvin-robot opened this issue Aug 3, 2021 · 1 comment
Closed

Task to Trigger Google Cloud Function #4836

marvin-robot opened this issue Aug 3, 2021 · 1 comment

Comments

@marvin-robot
Copy link
Member

Archived from the Prefect Public Slack Community

mattalhonte: Made a new version of the Task that triggers Google Cloud Functions - this one will actually fail if the Cloud Function doesn't work (my last version failed silently)

@task(max_retries=3, retry_delay=datetime.timedelta(seconds=30))
def trigger_cloud_fn(secret: PrefectSecret, url: str, body: str = "{}"):
    logger = prefect.context.get("logger")
    <http://logger.info|logger.info>(body)
    credentials = service_account.IDTokenCredentials.from_service_account_info(
        secret, target_audience=url
    )
    authed_session = AuthorizedSession(credentials)
    response = <http://authed_session.post|authed_session.post>(url=url, json=body)
    if not (isinstance(response, requests.models.Response) and response.ok):
        raise signals.FAIL()
    authed_session.close()
    return response

mattalhonte: I think logging the request body is also useful, cuz then you know which ones caused errors!

kevin701: <@ULVA73B9P> archive “Task to Trigger Google Cloud Function”"

marvin2: #4835

Original thread can be found here.

@kvnkho
Copy link
Contributor

kvnkho commented Aug 3, 2021

This was a duplicate due to an edit.

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

No branches or pull requests

2 participants