Adding properly

The .git folder messed up the initial commit.
This commit is contained in:
Matt Jadud
2025-11-30 17:18:41 -05:00
parent 80b55d1a3b
commit 23923b7be4
15 changed files with 1511 additions and 0 deletions

View File

@@ -0,0 +1,138 @@
-- name: doQueueJobIgnoreDupe :exec
INSERT INTO
jobs (
queue,
job,
execute_after,
job_status,
created_at,
updated_at,
remaining_attempts,
deduping_key
)
VALUES
(
?,
?,
?,
'queued',
unixepoch(),
unixepoch(),
?,
?
) ON CONFLICT (deduping_key, job_status)
WHERE
deduping_key != ''
AND (job_status = 'queued' OR job_status = 'fetched' OR job_status = 'completed') DO NOTHING;
-- name: doQueueJobReplaceDupe :exec
INSERT INTO
jobs (
queue,
job,
execute_after,
job_status,
created_at,
updated_at,
remaining_attempts,
deduping_key
)
VALUES
(
?,
?,
?,
'queued',
unixepoch(),
unixepoch(),
?,
?
) ON CONFLICT (deduping_key, job_status)
WHERE
deduping_key != ''
AND job_status = 'queued' DO
UPDATE
SET
job = EXCLUDED.job,
execute_after = EXCLUDED.execute_after,
updated_at = unixepoch(),
remaining_attempts = EXCLUDED.remaining_attempts;
-- name: CompleteJob :exec
UPDATE
jobs
SET
job_status = 'completed',
finished_at = unixepoch(),
updated_at = unixepoch(),
consumer_fetched_at = 0,
remaining_attempts = 0
WHERE
id = ?;
-- name: FailJob :exec
UPDATE
jobs
SET
job_status = CASE
WHEN remaining_attempts <= 1 THEN 'failed'
ELSE 'queued'
END,
finished_at = 0,
updated_at = unixepoch(),
consumer_fetched_at = 0,
remaining_attempts = MAX(remaining_attempts - 1, 0),
errors = ?
WHERE
id = ?;
-- name: MarkJobsForConsumer :many
UPDATE
jobs
SET
consumer_fetched_at = unixepoch(),
updated_at = unixepoch(),
job_status = 'fetched'
WHERE
jobs.job_status = 'queued'
AND jobs.remaining_attempts > 0
AND jobs.id IN (
SELECT
id
FROM
jobs js
WHERE
js.queue = ?
AND js.job_status = 'queued'
AND js.execute_after <= ?
AND js.remaining_attempts > 0
ORDER BY
execute_after ASC
LIMIT
?
) RETURNING *;
-- name: ResetJobs :execrows
UPDATE
jobs
SET
job_status = CASE
WHEN remaining_attempts <= 1 THEN 'failed'
ELSE 'queued'
END,
updated_at = unixepoch(),
consumer_fetched_at = 0,
remaining_attempts = MAX(remaining_attempts - 1, 0),
errors = json_insert(errors, '$[#]', 'visibility timeout expired')
WHERE
job_status = 'fetched'
AND queue = ?
AND consumer_fetched_at < ?;
-- name: FindJob :one
SELECT
*
FROM
jobs
WHERE
id = ?;

View File

@@ -0,0 +1,32 @@
PRAGMA journal_mode = WAL;
CREATE TABLE IF NOT EXISTS jobs (
id INTEGER NOT NULL,
queue TEXT NOT NULL,
job TEXT NOT NULL,
job_status TEXT NOT NULL DEFAULT 'queued',
execute_after INTEGER NOT NULL DEFAULT 0,
remaining_attempts INTEGER NOT NULL DEFAULT 1,
consumer_fetched_at INTEGER NOT NULL DEFAULT 0,
finished_at INTEGER NOT NULL DEFAULT 0,
deduping_key TEXT NOT NULL DEFAULT '',
errors TEXT NOT NULL DEFAULT "[]",
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
PRIMARY KEY (id)
);
CREATE INDEX IF NOT EXISTS todo ON jobs (queue, job_status, execute_after)
WHERE
job_status = 'queued'
OR job_status = 'fetched';
CREATE UNIQUE INDEX IF NOT EXISTS dedupe_ignore ON jobs (deduping_key, job_status)
WHERE
deduping_key != ''
AND (job_status = 'queued' OR job_status = 'fetched' OR job_status = 'completed');
CREATE UNIQUE INDEX IF NOT EXISTS dedupe_replace ON jobs (deduping_key, job_status)
WHERE
deduping_key != ''
AND job_status = 'queued';