complete.py
876 B · python · 29 lines
1import boto32import json3import os4from automator.core.api import logger5from automator.core.errors import NoTaskError6from automator.core.models import Task7from automator.core.s3 import archive_task, clear_task8from automator.core.steps import Step910SITE_FUNCTION = os.environ.get("CARLOMITCHENER_SITE_FUNCTION") or "carlomitchener-site"1112def wake_site() -> None:13 try:14 boto3.client("lambda").invoke(15 FunctionName=SITE_FUNCTION,16 InvocationType="Event",17 Payload=json.dumps({"source": "automator"}).encode(),18 )19 logger.info(f"woke {SITE_FUNCTION}")20 except Exception as error:21 logger.info(f"{SITE_FUNCTION} wake failed: {error}")2223def mrly_complete(task: Task) -> Task:24 task.wipe()25 task.place(Step.ARCHIVE)26 archive_task(task)27 clear_task()28 wake_site()29 raise NoTaskError(task.key)