feat(ai-studio): separate image pool from task states
This commit is contained in:
@@ -343,6 +343,7 @@ CREATE TABLE IF NOT EXISTS image_studio_jobs (
|
||||
status TEXT NOT NULL DEFAULT 'pending',
|
||||
prompt TEXT,
|
||||
error TEXT,
|
||||
recovery_action TEXT NOT NULL DEFAULT 'regenerate',
|
||||
attempts INTEGER NOT NULL DEFAULT 0,
|
||||
points_cost INTEGER,
|
||||
points_balance INTEGER,
|
||||
@@ -477,6 +478,7 @@ def init_db(path=None, conn=None) -> None:
|
||||
_ensure_batch_delete_columns(database)
|
||||
_ensure_task_image_task_columns(database)
|
||||
_ensure_task_cover_reset_columns(database)
|
||||
_ensure_image_studio_job_recovery_columns(database)
|
||||
|
||||
|
||||
def _ensure_batch_delete_columns(database):
|
||||
@@ -502,6 +504,37 @@ def _ensure_task_cover_reset_columns(database):
|
||||
if "cover_reset_at" not in columns:
|
||||
database.execute("ALTER TABLE tasks ADD COLUMN cover_reset_at TEXT")
|
||||
|
||||
|
||||
def _ensure_image_studio_job_recovery_columns(database):
|
||||
columns = {
|
||||
row["name"] for row in database.execute("PRAGMA table_info(image_studio_jobs)").fetchall()
|
||||
}
|
||||
if "recovery_action" not in columns:
|
||||
database.execute(
|
||||
"ALTER TABLE image_studio_jobs ADD COLUMN recovery_action TEXT NOT NULL DEFAULT 'regenerate'"
|
||||
)
|
||||
database.execute(
|
||||
"""
|
||||
UPDATE image_studio_jobs
|
||||
SET recovery_action = CASE
|
||||
WHEN status = 'succeeded' THEN 'none'
|
||||
WHEN task_id IS NOT NULL AND status IN ('submitted', 'running') THEN 'resume'
|
||||
ELSE 'regenerate'
|
||||
END
|
||||
WHERE recovery_action IS NULL
|
||||
OR recovery_action NOT IN ('none', 'resume', 'regenerate')
|
||||
OR (
|
||||
recovery_action = 'regenerate'
|
||||
AND task_id IS NOT NULL
|
||||
AND status IN ('submitted', 'running')
|
||||
)
|
||||
OR (
|
||||
recovery_action = 'regenerate'
|
||||
AND status = 'succeeded'
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
||||
def create_batch(file_paths: Iterable[str], note=None, path=None, conn=None) -> str:
|
||||
batch_id = datetime.now().strftime("%Y%m%d_%H%M%S_") + uuid.uuid4().hex[:8]
|
||||
files = [os.path.abspath(file_path) for file_path in file_paths]
|
||||
|
||||
Reference in New Issue
Block a user