Queue native collection launches before async placement

This commit is contained in:
2026-10-05 11:35:50 -04:00
parent 1405114a14
commit 7c76851252
34 changed files with 1324 additions and 244 deletions
+12
View File
@@ -439,6 +439,18 @@ function libraryInUse(versionId: string, hostId?: string): boolean {
if (!handle.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='native_instances'").get()) return true;
if (handle.prepare(`SELECT 1 FROM native_instances WHERE library_id=? AND retired_at IS NULL ${hostId ? 'AND host_id=?' : ''} LIMIT 1`)
.get(versionId, ...(hostId ? [hostId] : []))) return true;
// Accepted jobs pin their game files before placement creates an instance.
// Automatic intents may still choose any host, so retain each available copy.
if (handle.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='native_creation_intents'").get()
&& handle.prepare(`SELECT 1 FROM server_deployments d
JOIN native_creation_intents q ON q.deployment_id=d.id
LEFT JOIN native_provisioning n ON n.deployment_id=d.id
WHERE d.action='create' AND d.server_deleted_at IS NULL
AND d.state IN ('queued','waiting','running','awaiting-health','interrupted') AND n.deployment_id IS NULL
AND json_extract(q.selection,'$.libraryId')=?
${hostId ? `AND (json_extract(q.selection,'$.automatic')=1 OR json_extract(q.selection,'$.hostId') IS NULL
OR json_extract(q.selection,'$.hostId')=?)` : ''} LIMIT 1`)
.get(versionId, ...(hostId ? [hostId] : []))) return true;
return !!handle.prepare(`SELECT 1 FROM ec_host_operations WHERE state IN ('pending','accepted','running','unknown')
AND (json_extract(payload,'$.libraryVersionId')=? OR json_extract(payload,'$.libraryId')=? OR json_extract(payload,'$.importId')=?)
${hostId ? 'AND host_id=?' : ''} LIMIT 1`).get(versionId, versionId, versionId, ...(hostId ? [hostId] : []));
+5
View File
@@ -3,6 +3,11 @@ import type Database from 'better-sqlite3';
const initialized = new WeakSet<Database.Database>();
export function ensureGameFileSchema(handle: Database.Database): void {
if (initialized.has(handle)) return;
// Worker readers open only after the controller has initialized the schema.
if (handle.readonly) {
initialized.add(handle);
return;
}
handle.exec(`
CREATE TABLE IF NOT EXISTS game_file_libraries (
id TEXT PRIMARY KEY, name TEXT NOT NULL COLLATE NOCASE UNIQUE,