fase(8): sqlite job queue system
This commit is contained in:
36
dist/db/migrations/003_jobs_table.js
vendored
Normal file
36
dist/db/migrations/003_jobs_table.js
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.up = up;
|
||||
exports.down = down;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
async function up(db) {
|
||||
await db.schema.createTable('jobs')
|
||||
.ifNotExists()
|
||||
.addColumn('id', 'text', col => col.primaryKey())
|
||||
.addColumn('type', 'text', col => col.notNull())
|
||||
.addColumn('status', 'text', col => col.notNull().defaultTo('pending'))
|
||||
.addColumn('payload', 'text', col => col.notNull())
|
||||
.addColumn('result', 'text')
|
||||
.addColumn('error', 'text')
|
||||
.addColumn('attempts', 'integer', col => col.notNull().defaultTo(0))
|
||||
.addColumn('max_attempts', 'integer', col => col.notNull().defaultTo(3))
|
||||
.addColumn('priority', 'integer', col => col.notNull().defaultTo(0))
|
||||
.addColumn('run_at', 'text', col => col.notNull())
|
||||
.addColumn('started_at', 'text')
|
||||
.addColumn('completed_at', 'text')
|
||||
.addColumn('created_at', 'text', col => col.notNull())
|
||||
.addColumn('updated_at', 'text', col => col.notNull())
|
||||
.execute();
|
||||
// Index for efficient polling
|
||||
await db.schema
|
||||
.createIndex('idx_jobs_poll')
|
||||
.ifNotExists()
|
||||
.on('jobs')
|
||||
.columns(['status', 'run_at', 'priority'])
|
||||
.execute();
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
async function down(db) {
|
||||
await db.schema.dropIndex('idx_jobs_poll').ifExists().execute();
|
||||
await db.schema.dropTable('jobs').ifExists().execute();
|
||||
}
|
||||
Reference in New Issue
Block a user