"""Retry custom reports and statement attachments that are stuck.""" import logging import sys sys.path.append('') logging.basicConfig(level=logging.INFO) from moneyhub.config import Config # noqa: E402 from moneyhub.connectors import sqs # noqa: E402 from moneyhub.models import ReportCustom # noqa: E402 from moneyhub.models import StatementAttachment # noqa: E402 def _run(): """Get all the stuck reports and attachments and send SQS messages to generate them.""" custom_reports = ReportCustom.get_stuck_in_progress() if custom_reports: logging.info(f'Found {len(custom_reports)} stuck custom reports') messages = [] for report in custom_reports: logging.info(f'Generating report: {report.report_custom_id}') messages.append({'report_custom_id': report.report_custom_id}) sqs.send_messages( Config.SQS_MH_CUSTOM_REPORTS_QUEUE_NAME, None, messages) statement_attachments = StatementAttachment.get_stuck_in_progress() if statement_attachments: logging.info(f'Found {len(statement_attachments)} stuck statement attachments') messages = [] for attachment in statement_attachments: logging.info(f'Generating attachment: {attachment.statement_attachment_id}') messages.append({'statement_attachment_id': attachment.statement_attachment_id}) sqs.send_messages( Config.SQS_MH_GENERATE_ATTACHMENTS_QUEUE_NAME, None, messages) if __name__ == '__main__': _run()