Browse Source

fix: fix-app-site-missing command (#5714)

takatost 9 months ago
parent
commit
8e5569f773
1 changed files with 21 additions and 14 deletions
  1. 21 14
      api/commands.py

+ 21 - 14
api/commands.py

@@ -593,17 +593,22 @@ def fix_app_site_missing():
     """
     click.echo(click.style('Start fix app related site missing issue.', fg='green'))
 
+    failed_app_ids = []
     while True:
-        try:
-            sql = """select apps.id as id from apps left join sites on sites.app_id=apps.id
+        sql = """select apps.id as id from apps left join sites on sites.app_id=apps.id
 where sites.id is null limit 1000"""
-            with db.engine.begin() as conn:
-                rs = conn.execute(db.text(sql))
+        with db.engine.begin() as conn:
+            rs = conn.execute(db.text(sql))
+
+            processed_count = 0
+            for i in rs:
+                processed_count += 1
+                app_id = str(i.id)
+
+                if app_id in failed_app_ids:
+                    continue
 
-                processed_count = 0
-                for i in rs:
-                    processed_count += 1
-                    app_id = str(i.id)
+                try:
                     app = db.session.query(App).filter(App.id == app_id).first()
                     tenant = app.tenant
                     if tenant:
@@ -615,13 +620,15 @@ where sites.id is null limit 1000"""
                         account = accounts[0]
                         print("Fix app {} related site missing issue.".format(app.id))
                         app_was_created.send(app, account=account)
+                except Exception as e:
+                    failed_app_ids.append(app_id)
+                    click.echo(click.style('Fix app {} related site missing issue failed!'.format(app_id), fg='red'))
+                    logging.exception(f'Fix app related site missing issue failed, error: {e}')
+                    continue
+
+            if not processed_count:
+                break
 
-                if not processed_count:
-                    break
-        except Exception as e:
-            click.echo(click.style('Fix app related site missing issue failed!', fg='red'))
-            logging.exception(f'Fix app related site missing issue failed, error: {e}')
-            continue
 
     click.echo(click.style('Congratulations! Fix app related site missing issue successful!', fg='green'))