Skip to content

Commit 8f796f8

Browse files
feat(dgw): record provisioner tasks in gateway.db
A Task is the permanent record of work the provisioner asked Gateway to do: its kind, target and parameters, its state and a payload the kind defines. The work itself will run as a job on the job queue, which forgets it once done; the Task stays for status and auditing. The provisioner chooses the Task ID, so asking again with the same request returns the existing Task. At most one unfinished Task works on a target per kind, and a Task past its deadline is failed when another one asks for its target, so a lost job never blocks it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 3abb65b commit 8f796f8

7 files changed

Lines changed: 701 additions & 0 deletions

File tree

‎Cargo.lock‎

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
CREATE TABLE provisioner_task (
2+
id TEXT PRIMARY KEY,
3+
kind TEXT NOT NULL,
4+
target TEXT NOT NULL,
5+
params TEXT NOT NULL,
6+
state TEXT NOT NULL,
7+
payload TEXT NOT NULL,
8+
attempts INTEGER NOT NULL DEFAULT 0,
9+
created_at INTEGER NOT NULL,
10+
started_at INTEGER,
11+
finished_at INTEGER,
12+
deadline_at INTEGER NOT NULL,
13+
CHECK (state IN ('queued', 'running', 'succeeded', 'failed')),
14+
CHECK ((state IN ('succeeded', 'failed')) = (finished_at IS NOT NULL)),
15+
CHECK (json_valid(params) AND json_valid(payload)),
16+
CHECK (attempts >= 0)
17+
);
18+
19+
CREATE UNIQUE INDEX provisioner_task_unfinished ON provisioner_task (kind, target)
20+
WHERE state IN ('queued', 'running');

‎crates/gateway-db/src/lib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const PRAGMAS: &str = "
2828
const MIGRATIONS: &[&str] = &[
2929
include_str!("../migrations/01_agent_tunnel.sql"),
3030
include_str!("../migrations/02_prefix_agent_tunnel_tables.sql"),
31+
include_str!("../migrations/03_provisioner_task.sql"),
3132
];
3233

3334
/// The open `gateway.db`, ready to hand a connection to each feature that keeps tables in it.
@@ -247,6 +248,7 @@ mod tests {
247248
assert!(table_exists(&conn, "agent_tunnel_accepted_agents").await);
248249
assert!(table_exists(&conn, "agent_tunnel_enrollment_attempts").await);
249250
assert!(table_exists(&conn, "agent_tunnel_deleted_agent_keys").await);
251+
assert!(table_exists(&conn, "provisioner_task").await);
250252
assert!(!table_exists(&conn, "metadata").await);
251253
}
252254

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "provisioner-task-libsql"
3+
version = "0.0.0"
4+
edition = "2024"
5+
authors = ["Devolutions Inc. <infos@devolutions.net>"]
6+
publish = false
7+
8+
[lints]
9+
workspace = true
10+
11+
[dependencies]
12+
anyhow = "1"
13+
async-trait = "0.1"
14+
libsql = { version = "0.9", default-features = false, features = ["core"] }
15+
provisioner-task.path = "../provisioner-task"
16+
serde_json = "1"
17+
time = { version = "0.3", default-features = false }
18+
tokio = { version = "1.52", features = ["sync"] }
19+
tracing = "0.1"
20+
uuid = "1.23"
21+
22+
[dev-dependencies]
23+
gateway-db.path = "../gateway-db"
24+
tokio = { version = "1.52", features = ["macros", "rt-multi-thread"] }
25+
uuid = { version = "1.23", features = ["v4"] }

0 commit comments

Comments
 (0)