Reap draining account locks during heartbeat
This commit is contained in:
+12
-37
@@ -779,6 +779,8 @@ def newserv_account_lock_heartbeat():
|
|||||||
""", (expires_at, source))
|
""", (expires_at, source))
|
||||||
refreshed = cur.rowcount
|
refreshed = cur.rowcount
|
||||||
|
|
||||||
|
reaped, kept = reap_draining_account_locks()
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"ok": True,
|
"ok": True,
|
||||||
"source": source,
|
"source": source,
|
||||||
@@ -786,6 +788,8 @@ def newserv_account_lock_heartbeat():
|
|||||||
"source_ship": source_ship,
|
"source_ship": source_ship,
|
||||||
"refreshed": refreshed,
|
"refreshed": refreshed,
|
||||||
"expires_at": expires_at.isoformat(),
|
"expires_at": expires_at.isoformat(),
|
||||||
|
"reaped_draining_count": len(reaped),
|
||||||
|
"kept_draining_count": len(kept),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@@ -914,49 +918,20 @@ def newserv_account_lock_session_end():
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def reap_draining_account_locks():
|
||||||
|
reaped, kept = reap_draining_account_locks()
|
||||||
|
|
||||||
|
return reaped, kept
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/newserv/account-locks/reap-draining")
|
@app.post("/api/newserv/account-locks/reap-draining")
|
||||||
def newserv_account_lock_reap_draining():
|
def newserv_account_lock_reap_draining():
|
||||||
auth_error = require_newserv_shared_secret()
|
auth_error = require_newserv_shared_secret()
|
||||||
if auth_error:
|
if auth_error:
|
||||||
return auth_error
|
return auth_error
|
||||||
|
|
||||||
reaped = []
|
reaped, kept = reap_draining_account_locks()
|
||||||
kept = []
|
|
||||||
|
|
||||||
with connect() as conn:
|
|
||||||
with conn.transaction():
|
|
||||||
with conn.cursor(row_factory=psycopg.rows.dict_row) as cur:
|
|
||||||
cur.execute("""
|
|
||||||
SELECT account_id, holder_source, source_region, source_ship,
|
|
||||||
account_store, state, sessions, created_at, updated_at, expires_at
|
|
||||||
FROM account_session_locks
|
|
||||||
WHERE state = 'draining'
|
|
||||||
ORDER BY updated_at ASC
|
|
||||||
FOR UPDATE
|
|
||||||
""")
|
|
||||||
rows = list(cur.fetchall())
|
|
||||||
|
|
||||||
for row in rows:
|
|
||||||
account_id = row["account_id"]
|
|
||||||
current, sync = account_sync_current_on_all_regions(account_id)
|
|
||||||
|
|
||||||
if current:
|
|
||||||
cur.execute("""
|
|
||||||
DELETE FROM account_session_locks
|
|
||||||
WHERE account_id = %s
|
|
||||||
""", (account_id,))
|
|
||||||
reaped.append({
|
|
||||||
"account_id": account_id_str(account_id),
|
|
||||||
"holder_source": row["holder_source"],
|
|
||||||
"sync_status": sync.get("status"),
|
|
||||||
})
|
|
||||||
else:
|
|
||||||
kept.append({
|
|
||||||
"account_id": account_id_str(account_id),
|
|
||||||
"holder_source": row["holder_source"],
|
|
||||||
"sync_status": sync.get("status"),
|
|
||||||
"regions": sync.get("regions"),
|
|
||||||
})
|
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"ok": True,
|
"ok": True,
|
||||||
|
|||||||
Reference in New Issue
Block a user