Skip to content

Commit

Permalink
new fargate and github action build
Browse files Browse the repository at this point in the history
  • Loading branch information
sliu008 committed Jan 7, 2025
1 parent c04ea20 commit 41d8265
Show file tree
Hide file tree
Showing 14 changed files with 1,247 additions and 708 deletions.
462 changes: 144 additions & 318 deletions .github/workflows/build.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/release-created.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install Poetry
uses: abatilo/actions-poetry@v3
with:
poetry-version: 1.8.1
poetry-version: 1.8.5
- name: Bump minor version
env:
COMMIT_VERSION: ${{ github.ref }}
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/setup-python-poetry/action.yml
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.
77 changes: 77 additions & 0 deletions podaac/lambda_handler/cumulus_cli_handler/handlers.py
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
6 changes: 6 additions & 0 deletions podaac/lambda_handler/lambda_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from cumulus_logger import CumulusLogger
from cumulus_process import Process, s3
from podaac.forge_py import forge
from podaac.lambda_handler.cumulus_cli_handler.handlers import activity

cumulus_logger = CumulusLogger('forge_py')

Expand Down Expand Up @@ -250,6 +251,11 @@ def process(self):

return self.input

@classmethod
def cumulus_activity(cls, arn=os.getenv('ACTIVITY_ARN')):
""" Run an activity using Cumulus messaging (cumulus-message-adapter) """
activity(cls.cumulus_handler, arn)

@classmethod
def handler(cls, event, context=None, path=None, noclean=False):
""" General event handler """
Expand Down
2 changes: 1 addition & 1 deletion podaac/lambda_handler/lambda_handler_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class FootprintBranch(Process):
process()
main function ran for image generation
get_config()
downloads configuration file for tig
downloads configuration file for forge-py
"""

def __init__(self, *args, **kwargs):
Expand Down
Loading

0 comments on commit 41d8265

Please sign in to comment.