Skip to content

Commit

Permalink
fix: fix-app-site-missing command (#5714)
Browse files Browse the repository at this point in the history
  • Loading branch information
takatost authored Jun 28, 2024
1 parent d30c138 commit 8e5569f
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions api/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -615,13 +620,15 @@ def fix_app_site_missing():
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'))

Expand Down

0 comments on commit 8e5569f

Please sign in to comment.