feat: run durable image worker locally
Quality / test (push) Canceled after 0s

This commit is contained in:
2026-09-08 22:06:28 -04:00
parent abd574293b
commit dd8af7c140
6 changed files with 108 additions and 2 deletions
@@ -4,6 +4,7 @@ import test from 'node:test';
import {
createInMemoryImageDerivativeQueue,
processNextImageDerivativeJob,
processNextPersistentImageDerivativeJob,
runImageDerivativeJob,
} from '../src/image-derivative-worker.js';
@@ -66,4 +67,32 @@ test('claims queued jobs and persists their processing lifecycle', async () => {
assert.equal(result.status, 'COMPLETED');
assert.equal(queue.getJob('job-3').status, 'COMPLETED');
assert.equal(queue.getJob('job-3').derivatives[0].key, 'queued.jpg-thumbnail.webp');
});
test('claims and persists a durable image derivative job lifecycle', async () => {
const calls = [];
const jobRepository = {
async claimNext() {
return { id: 'job-4', sourceKey: 'durable.jpg', status: 'PROCESSING' };
},
async complete(id, derivatives) {
calls.push({ action: 'complete', id, derivatives });
},
async fail() {
throw new Error('A successful durable job must not fail.');
},
};
const result = await processNextPersistentImageDerivativeJob({
jobRepository,
async loadSource(sourceKey) { return { sourceKey, data: Buffer.from('image') }; },
processor: { async process() { return [{ name: 'thumbnail', key: 'durable-thumbnail.webp' }]; } },
});
assert.equal(result.status, 'COMPLETED');
assert.deepEqual(calls, [{
action: 'complete',
id: 'job-4',
derivatives: [{ name: 'thumbnail', key: 'durable-thumbnail.webp' }],
}]);
});