"""Stop all active executions in given swf domain.""" import datetime import logging import os import boto3 import dotenv from feed_ingestion.conf.config import BOTO3_CONFIG, ENV logger = logging.getLogger(__name__) script_dir = os.path.dirname(__file__) SWF_DOMAIN = os.environ['SWF_DOMAIN'] OLDEST_DATE = datetime.datetime.now() - datetime.timedelta(hours=24) def main(): """Stop all active executions in given swf domain.""" swf_client = boto3.client('swf', config=BOTO3_CONFIG) assert ENV in ['dev', 'test'], 'Not applicable for production' executions = swf_client.list_open_workflow_executions( domain=SWF_DOMAIN, startTimeFilter={ 'oldestDate': OLDEST_DATE }, )['executionInfos'] logger.info(f'Found {len(executions)} executions in {SWF_DOMAIN}') for execution in [e['execution'] for e in executions]: workflow_id = execution['workflowId'] run_id = execution['runId'] logger.warning( f'Stopping execution workflowId: "{workflow_id}"' f' runId: "{run_id}"') swf_client.terminate_workflow_execution( domain=SWF_DOMAIN, workflowId=workflow_id, runId=run_id, ) logger.info('All done') if __name__ == '__main__': logging.basicConfig(level=logging.INFO) dotenv.load_dotenv(f'{script_dir}/../../.env') main()