Update rule + flow hdfs new

This commit is contained in:
2026-09-23 11:36:34 +07:00
parent c79ea9f05f
commit 0e15bc89a8
10 changed files with 159 additions and 35 deletions

View File

@@ -30,7 +30,7 @@ class Store:
db.executescript("""
CREATE TABLE IF NOT EXISTS jobs (
id TEXT PRIMARY KEY, request_id TEXT NOT NULL UNIQUE,
file_path TEXT NOT NULL, callback_url TEXT, batch_id TEXT,
file_path TEXT NOT NULL, callback_url TEXT, batch_id TEXT, dag_run_id TEXT,
filename TEXT, source_kind TEXT NOT NULL DEFAULT 'path',
status TEXT NOT NULL, created_at REAL NOT NULL, updated_at REAL NOT NULL,
total_pages INTEGER NOT NULL DEFAULT 0,
@@ -63,6 +63,8 @@ class Store:
db.execute("ALTER TABLE jobs ADD COLUMN filename TEXT")
if "source_kind" not in columns:
db.execute("ALTER TABLE jobs ADD COLUMN source_kind TEXT NOT NULL DEFAULT 'path'")
if "dag_run_id" not in columns:
db.execute("ALTER TABLE jobs ADD COLUMN dag_run_id TEXT")
@contextmanager
def tx(self):
@@ -83,24 +85,25 @@ class Store:
def create_job(self, request_id: str, file_path: str, callback_url: str | None,
batch_id: str | None, max_queued: int, filename: str | None = None,
source_kind: str = "path"):
source_kind: str = "path", dag_run_id: str | None = None):
now = time.time()
filename = filename or Path(file_path).name
with self.tx() as db:
prior = db.execute("SELECT * FROM jobs WHERE request_id=?", (request_id,)).fetchone()
if prior:
if (prior["file_path"], prior["callback_url"], prior["batch_id"],
prior["filename"]) != (file_path, callback_url, batch_id, filename):
prior["filename"], prior["dag_run_id"]) != (file_path, callback_url, batch_id,
filename, dag_run_id):
raise ValueError("request_id already exists with different inputs")
return self.as_dict(prior), False
queued = db.execute("SELECT count(*) FROM jobs WHERE status IN ('queued','preparing','processing','finalizing')").fetchone()[0]
if queued >= max_queued:
raise OverflowError("Job queue is full")
job_id = "job_" + uuid4().hex
db.execute("""INSERT INTO jobs(id,request_id,file_path,callback_url,batch_id,filename,
db.execute("""INSERT INTO jobs(id,request_id,file_path,callback_url,batch_id,dag_run_id,filename,
source_kind,status,created_at,updated_at)
VALUES(?,?,?,?,?,?,?,'queued',?,?)""",
(job_id, request_id, file_path, callback_url, batch_id, filename,
VALUES(?,?,?,?,?,?,?,?,'queued',?,?)""",
(job_id, request_id, file_path, callback_url, batch_id, dag_run_id, filename,
source_kind, now, now))
return self.as_dict(db.execute("SELECT * FROM jobs WHERE id=?", (job_id,)).fetchone()), True