-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,247 additions
and
708 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# .github/actions/setup-python-poetry/action.yml | ||
name: 'Setup Python and Poetry' | ||
description: 'Sets up Python and Poetry with caching' | ||
|
||
inputs: | ||
python-version: | ||
description: 'Python version to use' | ||
required: true | ||
poetry-version: | ||
description: 'Poetry version to use' | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ inputs.python-version }} | ||
cache: 'pip' | ||
|
||
- uses: abatilo/actions-poetry@v3 | ||
with: | ||
poetry-version: ${{ inputs.poetry-version }} | ||
|
||
- name: Setup Poetry cache | ||
shell: bash | ||
run: | | ||
poetry config virtualenvs.in-project true | ||
- uses: actions/cache@v4 | ||
with: | ||
path: .venv | ||
key: venv-${{ runner.os }}-${{ inputs.python-version }}-${{ hashFiles('**/poetry.lock') }} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
"""Handler module for ecs activity""" | ||
|
||
import os | ||
import json | ||
import signal | ||
import sys | ||
import traceback | ||
from functools import partial | ||
import boto3 | ||
from botocore.client import Config | ||
from botocore.vendored.requests.exceptions import ReadTimeout | ||
from cumulus_logger import CumulusLogger | ||
|
||
logger = CumulusLogger('image_generator_activity') | ||
|
||
""" | ||
cls is the Process subclass for a specific data source, such as MODIS, ASTER, etc. | ||
""" | ||
|
||
SFN_PAYLOAD_LIMIT = 32768 | ||
TASK_TOKEN = None | ||
|
||
|
||
def shutdown(sfn, signum, frame): # pylint: disable=W0613 | ||
"""Shutdown function when getting termination signal for ecs""" | ||
logger.info("Caught SIGTERM, shutting down") | ||
if TASK_TOKEN: | ||
ecs_error = "Caught SIGTERM, ECS is terminating container" | ||
sfn.send_task_failure(taskToken=TASK_TOKEN, error=ecs_error) | ||
logger.info("ECS service have been terminated last token: {}".format(TASK_TOKEN)) | ||
# Finish any outstanding requests, then... | ||
sys.exit(0) | ||
|
||
|
||
def activity(handler, arn=os.getenv('ACTIVITY_ARN')): | ||
""" An activity service for use with AWS Step Functions """ | ||
sfn = boto3.client('stepfunctions', config=Config(read_timeout=70)) | ||
signal.signal(signal.SIGTERM, partial(shutdown, sfn)) | ||
while True: | ||
get_and_run_task(handler, sfn, arn) | ||
|
||
|
||
def get_and_run_task(handler, sfn, arn): | ||
""" Get and run a single task as part of an activity """ | ||
global TASK_TOKEN # pylint: disable=W0603 | ||
logger.info("query for task") | ||
try: | ||
task = sfn.get_activity_task(activityArn=arn, workerName=__name__) | ||
except ReadTimeout: | ||
logger.warning("Activity read timed out. Trying again.") | ||
return | ||
|
||
token = task.get('taskToken', None) | ||
if not token: | ||
logger.info("No activity task") | ||
return | ||
TASK_TOKEN = token | ||
|
||
try: | ||
payload = json.loads(task['input']) | ||
output = json.dumps(handler(event=payload)) | ||
sfn.send_task_success(taskToken=task['taskToken'], output=output) | ||
TASK_TOKEN = None | ||
except MemoryError as ex: | ||
err = str(ex) | ||
logger.error("Memory error when running task: {}".format(err)) | ||
trace_back = traceback.format_exc() | ||
err = (err[252] + ' ...') if len(err) > 252 else err | ||
sfn.send_task_failure(taskToken=task['taskToken'], error=str(err), cause=trace_back) | ||
raise ex | ||
except Exception as ex: # pylint: disable=W0703 | ||
err = str(ex) | ||
logger.error("Exception when running task: {}".format(err)) | ||
trace_back = traceback.format_exc() | ||
err = (err[252] + ' ...') if len(err) > 252 else err | ||
sfn.send_task_failure(taskToken=task['taskToken'], error=str(err), cause=trace_back) | ||
TASK_TOKEN = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.