https://prefect.io logo
Title
m

matta

08/03/2021, 4:21 AM
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: t.Dict = dict()):
    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
❤️ 9
I think logging the request body is also useful, cuz then you know which ones caused errors!
k

Kevin Kho

08/03/2021, 5:56 PM
@Marvin archive “Task to Trigger Google Cloud Function”"