def delete_domain(custom_domain_id: CustomDomain): from server import create_light_app with create_light_app().app_context(): custom_domain = CustomDomain.get(custom_domain_id) if not custom_domain: return domain_name = custom_domain.domain user = custom_domain.user CustomDomain.delete(custom_domain.id) db.session.commit() LOG.d("Domain %s deleted", domain_name) send_email( user.email, f"Your domain {domain_name} has been deleted", f"""Domain {domain_name} along with its aliases are deleted successfully. Regards, SimpleLogin team. """, )
def new_app(): app = create_light_app() @app.teardown_appcontext def shutdown_session(response_or_exc): # same as shutdown_session() in flask-sqlalchemy but this is not enough db.session.remove() # dispose the engine too db.engine.dispose() return app
def delete_mailbox(mailbox_id: int): from server import create_light_app with create_light_app().app_context(): mailbox = Mailbox.get(mailbox_id) if not mailbox: return mailbox_email = mailbox.email user = mailbox.user Mailbox.delete(mailbox_id) db.session.commit() LOG.d("Mailbox %s %s deleted", mailbox_id, mailbox_email) send_email( user.email, f"Your mailbox {mailbox_email} has been deleted", f"""Mailbox {mailbox_email} along with its aliases are deleted successfully. Regards, SimpleLogin team. """, )
"stats", "notify_trial_end", "notify_manual_subscription_end", "notify_premium_end", "delete_logs", "poll_apple_subscription", "sanity_check", "delete_old_monitoring", "check_custom_domain", "check_hibp", "notify_hibp", ], ) args = parser.parse_args() # wrap in an app context to benefit from app setup like database cleanup, sentry integration, etc with create_light_app().app_context(): if args.job == "stats": LOG.d("Compute growth and daily monitoring stats") stats() elif args.job == "notify_trial_end": LOG.d("Notify users with trial ending soon") notify_trial_end() elif args.job == "notify_manual_subscription_end": LOG.d("Notify users with manual subscription ending soon") notify_manual_sub_end() elif args.job == "notify_premium_end": LOG.d("Notify users with premium ending soon") notify_premium_end() elif args.job == "delete_logs": LOG.d("Deleted Logs") delete_logs()