def test_payments_marked_for_delete(session): """Assert a payment is stored. Start with a blank database. """ payment = factory_payment() payment.payment_status_code = PaymentStatus.DELETE_ACCEPTED.value payment.save() assert payment.id is not None payments = Payment.find_payments_marked_for_delete() assert len(payments) == 1
def delete_marked_payments(app): """Update stale payment records. This is to handle edge cases where the user has completed payment and some error occured and payment status is not up-to-date. """ payments_to_delete = PaymentModel.find_payments_marked_for_delete() if len(payments_to_delete) == 0: app.logger.info( f'Delete Payment Job Ran at {datetime.datetime.now()}.But No records found!' ) for payment in payments_to_delete: try: app.logger.info( 'Delete Payment Job found records.Payment Id: {}'.format( payment.id)) PaymentService.delete_payment(payment.id) app.logger.info( 'Delete Payment Job Updated records.Payment Id: {}'.format( payment.id)) except BusinessException as err: # just catch and continue .Don't stop app.logger.error('Error on delete_payment') app.logger.error(err)