| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import assert from 'node:assert/strict';
- import test from 'node:test';
- import type { ParseRestClient } from '../src/db/parse-rest.client.js';
- import { VOC_PARSE_CLASSES } from '../src/db/parse-rest.schema.js';
- import {
- ParseRestManagedTaskQueue,
- startParseRestManagedTaskWorker,
- } from '../src/modules/managed-tasks/parse-rest-managed-task-worker.js';
- test('managed task queue discovers and deduplicates workspaces across both queue classes', async () => {
- const client = {
- async find(className: string) {
- assert.ok([
- VOC_PARSE_CLASSES.competitorListingRefreshRun,
- VOC_PARSE_CLASSES.listingScoreJob,
- ].includes(className as never));
- return className === VOC_PARSE_CLASSES.competitorListingRefreshRun
- ? { results: [{ workspaceId: 'workspace-b' }, { workspaceId: 'workspace-a' }] }
- : { results: [{ workspaceId: 'workspace-a' }, { workspaceId: '' }, {}] };
- },
- } as unknown as ParseRestClient;
- assert.deepEqual(
- await new ParseRestManagedTaskQueue(client).listPendingWorkspaceIds(),
- ['workspace-a', 'workspace-b'],
- );
- });
- test('managed task worker resumes competitor and listing jobs and stops cleanly', async () => {
- let queueCalls = 0;
- const refreshCalls: string[] = [];
- const scoreCalls: string[] = [];
- const worker = startParseRestManagedTaskWorker({
- queue: {
- async listPendingWorkspaceIds() {
- queueCalls += 1;
- return queueCalls === 1 ? ['workspace-a'] : [];
- },
- },
- processor: {
- async resumePendingRefreshes(workspaceId, platform) {
- refreshCalls.push(`${workspaceId}:${platform}`);
- return 1;
- },
- async resumePendingJobs(workspaceId) {
- scoreCalls.push(workspaceId);
- return 1;
- },
- },
- pollMs: 5,
- logger: { log() {}, error() {} },
- });
- for (let attempt = 0; attempt < 50 && queueCalls === 0; attempt += 1) {
- await new Promise((resolve) => setTimeout(resolve, 2));
- }
- await worker.stop();
- assert.deepEqual(refreshCalls, ['workspace-a:jd']);
- assert.deepEqual(scoreCalls, ['workspace-a']);
- });
|