Molodetz blogrol volgens DPP-template
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
from molodetz.database.core import db, generate_uid, now_iso
|
||||
|
||||
|
||||
def enqueue_backup(target, requested_by):
|
||||
row = {
|
||||
"uid": generate_uid(),
|
||||
"target": target,
|
||||
"status": "pending",
|
||||
"requested_by": requested_by,
|
||||
"directory": None,
|
||||
"stored_name": None,
|
||||
"size_bytes": None,
|
||||
"error": None,
|
||||
"created_at": now_iso(),
|
||||
"finished_at": None,
|
||||
}
|
||||
db["backups"].insert(row)
|
||||
return row
|
||||
|
||||
|
||||
def pending_backups():
|
||||
if "backups" not in db.tables:
|
||||
return []
|
||||
return list(db["backups"].find(status="pending", order_by=["uid"]))
|
||||
|
||||
|
||||
def list_backups(limit=100):
|
||||
if "backups" not in db.tables:
|
||||
return []
|
||||
return list(db["backups"].find(order_by=["-created_at"], _limit=limit))
|
||||
|
||||
|
||||
def get_backup(uid):
|
||||
if "backups" not in db.tables:
|
||||
return None
|
||||
return db["backups"].find_one(uid=uid)
|
||||
|
||||
|
||||
def update_backup(uid, **fields):
|
||||
fields["uid"] = uid
|
||||
db["backups"].update(fields, ["uid"])
|
||||
|
||||
|
||||
def delete_backup_rows(uids):
|
||||
for uid in uids:
|
||||
db["backups"].delete(uid=uid)
|
||||
Reference in New Issue
Block a user