shoehorning graphql, step functions and lamdas. aws deployment scripts
This commit is contained in:
@@ -110,7 +110,16 @@ class LocalExecutor(Executor):
|
||||
|
||||
|
||||
class LambdaExecutor(Executor):
|
||||
"""Execute jobs via AWS Lambda (future implementation)."""
|
||||
"""Execute jobs via AWS Step Functions + Lambda."""
|
||||
|
||||
def __init__(self):
|
||||
import boto3
|
||||
|
||||
region = os.environ.get("AWS_REGION", "us-east-1")
|
||||
self.sfn = boto3.client("stepfunctions", region_name=region)
|
||||
self.state_machine_arn = os.environ["STEP_FUNCTION_ARN"]
|
||||
self.callback_url = os.environ.get("CALLBACK_URL", "")
|
||||
self.callback_api_key = os.environ.get("CALLBACK_API_KEY", "")
|
||||
|
||||
def run(
|
||||
self,
|
||||
@@ -123,8 +132,36 @@ class LambdaExecutor(Executor):
|
||||
duration: Optional[float] = None,
|
||||
progress_callback: Optional[Callable[[int, Dict[str, Any]], None]] = None,
|
||||
) -> bool:
|
||||
"""Execute job via AWS Lambda."""
|
||||
raise NotImplementedError("LambdaExecutor not yet implemented")
|
||||
"""Start a Step Functions execution for this job."""
|
||||
import json
|
||||
|
||||
payload = {
|
||||
"job_id": job_id,
|
||||
"source_key": source_path,
|
||||
"output_key": output_path,
|
||||
"preset": preset,
|
||||
"trim_start": trim_start,
|
||||
"trim_end": trim_end,
|
||||
"duration": duration,
|
||||
"callback_url": self.callback_url,
|
||||
"api_key": self.callback_api_key,
|
||||
}
|
||||
|
||||
response = self.sfn.start_execution(
|
||||
stateMachineArn=self.state_machine_arn,
|
||||
name=f"mpr-{job_id}",
|
||||
input=json.dumps(payload),
|
||||
)
|
||||
|
||||
# Store execution ARN on the job
|
||||
execution_arn = response["executionArn"]
|
||||
try:
|
||||
from mpr.media_assets.models import TranscodeJob
|
||||
TranscodeJob.objects.filter(id=job_id).update(execution_arn=execution_arn)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return True
|
||||
|
||||
|
||||
# Executor registry
|
||||
|
||||
Reference in New Issue
Block a user