feat: "Fazer backup agora" in Integrações
All checks were successful
Build and deploy / Validate source (push) Successful in 9s
Build and deploy / Integration suite on a real stack (push) Successful in 4m40s
Build and deploy / Secret scan and release gate (push) Successful in 13s
Build and deploy / Publish images (push) Successful in 1m29s
All checks were successful
Build and deploy / Validate source (push) Successful in 9s
Build and deploy / Integration suite on a real stack (push) Successful in 4m40s
Build and deploy / Secret scan and release gate (push) Successful in 13s
Build and deploy / Publish images (push) Successful in 1m29s
The backup row gets a button that asks for a backup outside the daily hour, for after a failure or before a risky change. The Kanban records the request; the backup service, which alone may read the whole database, looks every minute and runs it. The row says it was asked for until it runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -43,6 +43,8 @@ PREFIX = 'db/'
|
||||
RETRY = timedelta(hours=1)
|
||||
# A backup older than this means the daily run has stopped working.
|
||||
STALE = timedelta(hours=26)
|
||||
# How often the service looks for a "Fazer backup agora" from the Kanban.
|
||||
POLL = 60
|
||||
TABLES = ('orders', 'quotes', 'uploads', 'accounts', 'movements', 'payment_intents')
|
||||
|
||||
|
||||
@@ -167,8 +169,13 @@ def serve():
|
||||
now = datetime.now(timezone.utc)
|
||||
# A fresh deployment, or one that missed a day, backs up straight away.
|
||||
due = now if previous is None or now - previous > STALE else next_run(now, hour)
|
||||
checked = now
|
||||
while True:
|
||||
time.sleep(max(0, (due - datetime.now(timezone.utc)).total_seconds()))
|
||||
now = datetime.now(timezone.utc)
|
||||
if now < due and not requested_since(checked):
|
||||
time.sleep(min(POLL, (due - now).total_seconds()))
|
||||
continue
|
||||
checked = datetime.now(timezone.utc)
|
||||
try:
|
||||
run_once()
|
||||
due = next_run(datetime.now(timezone.utc), hour)
|
||||
@@ -176,6 +183,16 @@ def serve():
|
||||
due = datetime.now(timezone.utc) + RETRY
|
||||
|
||||
|
||||
def requested_since(moment):
|
||||
"""Whether someone asked for a backup in the Kanban after `moment`."""
|
||||
try:
|
||||
with admin_connect() as c:
|
||||
return c.execute('SELECT 1 FROM dtf_local.backup_requests WHERE requested_at>%s LIMIT 1',
|
||||
(moment,)).fetchone() is not None
|
||||
except psycopg.Error:
|
||||
return False
|
||||
|
||||
|
||||
def listing():
|
||||
client, name = bucket()
|
||||
keys = []
|
||||
|
||||
Reference in New Issue
Block a user