A nightly Dagster job backs up the data folder
This commit is contained in:
+27
-1
@@ -1,12 +1,14 @@
|
|||||||
"""Dagster code location: every heavy step of the platform is a job defined here."""
|
"""Dagster code location: every heavy step of the platform is a job defined here."""
|
||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
|
import os
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
import dagster as dg
|
import dagster as dg
|
||||||
|
|
||||||
from models import graph
|
from models import graph
|
||||||
from models.jobs import EmptyCohort
|
from models.jobs import EmptyCohort
|
||||||
|
from persistance import backup as backups
|
||||||
from persistance import config_log, silver
|
from persistance import config_log, silver
|
||||||
|
|
||||||
WRITES = {"writes": "platform"} # dagster.yaml lets one run with this tag at a time (SQLite)
|
WRITES = {"writes": "platform"} # dagster.yaml lets one run with this tag at a time (SQLite)
|
||||||
@@ -105,4 +107,28 @@ def analyze():
|
|||||||
analyze_studies()
|
analyze_studies()
|
||||||
|
|
||||||
|
|
||||||
defs = dg.Definitions(jobs=[ingest, train, score, analyze])
|
@dg.op
|
||||||
|
def make_backup(context: dg.OpExecutionContext) -> str:
|
||||||
|
"""The data folder into BACKUP_DIR (persistance.backup); the newest BACKUP_KEEP stay."""
|
||||||
|
folder = backups.create()
|
||||||
|
context.log.info(f"backup {folder}")
|
||||||
|
return str(folder)
|
||||||
|
|
||||||
|
|
||||||
|
@dg.job(tags=WRITES) # holds the writing slot: nothing writes while it copies
|
||||||
|
def backup():
|
||||||
|
make_backup()
|
||||||
|
|
||||||
|
|
||||||
|
# Nightly by default; BACKUP_SCHEDULE is a cron expression (empty: no schedule).
|
||||||
|
nightly = (
|
||||||
|
[
|
||||||
|
dg.ScheduleDefinition(
|
||||||
|
job=backup, cron_schedule=cron, default_status=dg.DefaultScheduleStatus.RUNNING
|
||||||
|
)
|
||||||
|
] # fmt: skip
|
||||||
|
if (cron := os.environ.get("BACKUP_SCHEDULE", "30 2 * * *"))
|
||||||
|
else []
|
||||||
|
)
|
||||||
|
|
||||||
|
defs = dg.Definitions(jobs=[ingest, train, score, analyze, backup], schedules=nightly)
|
||||||
|
|||||||
Reference in New Issue
Block a user