diff --git a/projects/tentacles/src/tentacles/blueprints/api.py b/projects/tentacles/src/tentacles/blueprints/api.py index 1f9b9a5..a16eef6 100644 --- a/projects/tentacles/src/tentacles/blueprints/api.py +++ b/projects/tentacles/src/tentacles/blueprints/api.py @@ -119,6 +119,7 @@ def create_file(location: Optional[str] = None): fid=row.id, cid=None, pid=None, + cont=False, # FIXME: How to decide this? ) return {"status": "ok"}, 202 diff --git a/projects/tentacles/src/tentacles/blueprints/job_ui.py b/projects/tentacles/src/tentacles/blueprints/job_ui.py index d9ae2fa..03d6466 100644 --- a/projects/tentacles/src/tentacles/blueprints/job_ui.py +++ b/projects/tentacles/src/tentacles/blueprints/job_ui.py @@ -39,17 +39,20 @@ def manipulate_jobs(): fid=int(request.form.get("file_id")), cid=maybe(int, request.form.get("color_id")), pid=maybe(int, request.form.get("printer_id")), + cont=request.form.get("continuous") == "on", ) flash("Job created!", category="info") case "duplicate": if job := ctx.db.fetch_job( - uid=ctx.uid, jid=int(request.form.get("job_id")) + uid=ctx.uid, + jid=int(request.form.get("job_id")), ): ctx.db.create_job( uid=ctx.uid, fid=job.file_id, cid=job.color_id, + cont=job.continuous, # FIXME: Need to dissociate job copies from the original mapped printer. Can't tell the difference # between the requested printer in the original job and the mapped printer from a scheduler run. pid=None, diff --git a/projects/tentacles/src/tentacles/sql/jobs.sql b/projects/tentacles/src/tentacles/sql/jobs.sql index 990f485..19973f4 100644 --- a/projects/tentacles/src/tentacles/sql/jobs.sql +++ b/projects/tentacles/src/tentacles/sql/jobs.sql @@ -27,10 +27,13 @@ CREATE TABLE IF NOT EXISTS jobs ( ); -- name: migration-0001-jobs-add-print-time# -ALTER TABLE jobs ADD COLUMN IF NOT EXISTS time_left INTEGER DEFAULT (0); +ALTER TABLE jobs ADD COLUMN time_left INTEGER DEFAULT (0); -- name: migration-0002-jobs-add-print-color# -ALTER TABLE jobs ADD COLUMN IF NOT EXISTS color_id INTEGER DEFAULT (NULL); +ALTER TABLE jobs ADD COLUMN color_id INTEGER DEFAULT (NULL); + +-- name: migration-0003-jobs-add-continuous# +ALTER TABLE jobs ADD COLUMN continuous BOOLEAN DEFAULT (FALSE); -- name: create-job^ INSERT INTO jobs ( @@ -38,12 +41,14 @@ INSERT INTO jobs ( , file_id , color_id , printer_id + , continuous ) VALUES ( :uid , :fid , :cid , :pid + , :cont ) RETURNING * @@ -78,36 +83,46 @@ WHERE -- name: list-job-queue SELECT - j.id as id - , j.file_id - , coalesce(j.color_id, fa.color_id) as color_id - , fa.id as analysis_id - , fa.max_x - , fa.max_y - , fa.max_z - , fa.max_bed - , fa.max_end - , fa.nozzle_diameter - , fa.filament_id - , (SELECT name FROM filament WHERE id = fa.filament_id) AS filament_name - , (SELECT name AS name FROM filament_color WHERE id = coalesce(j.color_id, fa.color_id)) AS color_name - , (SELECT name FROM job_statuses WHERE id = j.status_id) AS status - , j.started_at - , j.time_left - , j.cancelled_at - , j.finished_at - , j.user_id - , j.printer_id -FROM jobs j -INNER JOIN files f - ON j.file_id = f.id -LEFT JOIN file_analysis fa - ON fa.file_id = f.id -WHERE - finished_at IS NULL - AND cancelled_at IS NULL - AND (:uid IS NULL OR j.user_id = :uid) - AND f.id IS NOT NULL + * +FROM ( + SELECT + j.id as id + , j.file_id + , coalesce(j.color_id, fa.color_id) as color_id + , fa.id as analysis_id + , fa.max_x + , fa.max_y + , fa.max_z + , fa.max_bed + , fa.max_end + , fa.nozzle_diameter + , fa.filament_id + , (SELECT name FROM filament WHERE id = fa.filament_id) AS filament_name + , (SELECT name AS name FROM filament_color WHERE id = coalesce(j.color_id, fa.color_id)) AS color_name + , j.status_id + , (SELECT name FROM job_statuses WHERE id = j.status_id) AS status + , j.started_at + , j.time_left + , j.cancelled_at + , j.finished_at + , j.user_id + , j.printer_id + , j.continuous + FROM jobs j + INNER JOIN files f + ON j.file_id = f.id + LEFT JOIN file_analysis fa + ON fa.file_id = f.id + WHERE + finished_at IS NULL + AND cancelled_at IS NULL + AND (:uid IS NULL OR j.user_id = :uid) + AND f.id IS NOT NULL +) +ORDER BY + status_id DESC + , continuous DESC + , id ; -- name: poll-job-queue^ diff --git a/projects/tentacles/src/tentacles/templates/jobs_list.html.j2 b/projects/tentacles/src/tentacles/templates/jobs_list.html.j2 index 6ccd812..77e2bf5 100644 --- a/projects/tentacles/src/tentacles/templates/jobs_list.html.j2 +++ b/projects/tentacles/src/tentacles/templates/jobs_list.html.j2 @@ -9,32 +9,14 @@ {{ctx.db.fetch_file(ctx.uid, job.file_id).filename or "it's a secret"}} - {% if job.printer_id %} -