""" Task status management functions via DynamoDB. Similar to feed_status.py but used to check individual task statuses to see if they can be safely skipped. This uses the same DynamoDB items created by the feed_status functions, but uses a different attribute. There are no pre-set constants of task statuses, and these functions are not considered a replacement for feed_status functions. """ from garcon.contrib.dynamo_feed_status import \ feed_status_ingestion as feed_status def get_completed_tasks(feed_name, datestamp): """Return a list of completed tasks for execution lookup params. This does not have different behavior if the task does not exist in DynamoDB. Consider a non existing task execution as simply not having any completed tasks instead of an exception. Args: feed_name (str): Feed name of workflow execution for status updates. datestamp (str): Workflow generated date. Returns: list: List of task names, empty list if no tasks are completed. """ status_item = feed_status._get_item(feed_name, datestamp) if not status_item: return [] # this is called with _status at the end because the feed_status.set_status # function appends it automatically. tasks = status_item.get('completed_tasks_status', '').split(',') return tasks if any(tasks) else [] def is_completed_task(feed_name, datestamp, task_name): """Check DynamoDB for task completion status. Args: feed_name (str): Feed name of workflow execution for status updates. datestamp (str): Workflow generated date. task_name (str): Name of task. Returns: bool: True if task_name is found in marker attribute of DynamoDB item. """ return task_name in get_completed_tasks(feed_name, datestamp) def mark_completed_task(feed_name, datestamp, task_name): """Update DynamoDB item with task completion status note. Args: feed_name (str): Feed name of workflow execution for status updates. datestamp (str): Workflow generated date. task_name (str): Name of task. """ completed_tasks = get_completed_tasks(feed_name, datestamp) if task_name not in completed_tasks: completed_tasks.append(task_name) feed_status.set_status( feed_name, datestamp, 'completed_tasks', ','.join(completed_tasks))