@detiq/crawler 1.1.25 → 1.1.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/crawler.js +2 -3
- package/dist/crawler.js.map +2 -2
- package/dist/job-queue.js +299 -64
- package/dist/job-queue.js.map +3 -3
- package/package.json +1 -1
- package/src/crawler.ts +5 -2
- package/src/failure-analysis-agent.ts +2 -1
- package/src/job-queue.ts +373 -74
- package/types/crawler.d.ts +4 -0
- package/types/job-queue.d.ts +44 -3
package/types/crawler.d.ts
CHANGED
|
@@ -167,6 +167,10 @@ export declare function crawlProject(opts: {
|
|
|
167
167
|
/** When false, disables the puppeteer-extra stealth plugin (playwright-extra) for this crawl.
|
|
168
168
|
* Default true — stealth is applied unless explicitly set to false. */
|
|
169
169
|
stealth?: boolean;
|
|
170
|
+
/** Desktop viewport width in pixels (default: 1440). */
|
|
171
|
+
viewportWidth?: number;
|
|
172
|
+
/** Desktop viewport height in pixels (default: 900). */
|
|
173
|
+
viewportHeight?: number;
|
|
170
174
|
/** Called every 10 successful screen captures with current visited URLs and remaining queue — used for checkpoint persistence. */
|
|
171
175
|
onCheckpoint?: (visitedUrls: string[], pendingQueue: string[]) => Promise<void>;
|
|
172
176
|
/** Discovery mode only: called after each page with the current set of discovered original URLs — enables streaming partial results to callers. */
|
package/types/job-queue.d.ts
CHANGED
|
@@ -13,6 +13,13 @@
|
|
|
13
13
|
* (JOB_QUEUE_BACKEND=sqs, see sqs-queue.ts) for horizontally-scaled crawler
|
|
14
14
|
* fleets; every other job type always goes through the DB-backed queue.
|
|
15
15
|
*/
|
|
16
|
+
export declare enum FailureType {
|
|
17
|
+
TRANSIENT = "TRANSIENT",// network timeout, rate limit, 429, 503
|
|
18
|
+
INFRASTRUCTURE = "INFRASTRUCTURE",// DB connection, OOM, worker crash
|
|
19
|
+
LOGICAL = "LOGICAL",// bad input, business rule violation, 400/422
|
|
20
|
+
FATAL = "FATAL"
|
|
21
|
+
}
|
|
22
|
+
export declare function classifyFailure(error: string | Error | unknown): FailureType;
|
|
16
23
|
export declare function generateTOTP(secret: string): string;
|
|
17
24
|
export interface PlatformJobConfig {
|
|
18
25
|
tenantId: string;
|
|
@@ -114,6 +121,7 @@ export interface PlatformJobConfig {
|
|
|
114
121
|
/** Set on role-crawl sub-jobs — profile name tagged on discovered screens via roleAccess column. */
|
|
115
122
|
roleProfileName?: string;
|
|
116
123
|
}
|
|
124
|
+
export declare function getActiveExecutionCount(): number;
|
|
117
125
|
type ClaimedJob = {
|
|
118
126
|
id: string;
|
|
119
127
|
tenantId: string;
|
|
@@ -144,7 +152,9 @@ export declare function requeueOrphanedJobs(): Promise<void>;
|
|
|
144
152
|
/** Dispatches a claimed job to its type's processor. Last-resort safety net — every
|
|
145
153
|
* process*Job function already catches and records its own failures. */
|
|
146
154
|
export declare function dispatchClaimedJob(job: ClaimedJob): Promise<void>;
|
|
147
|
-
/** Re-promotes FAILED jobs to
|
|
155
|
+
/** Re-promotes FAILED jobs to RETRY_WAIT if they are eligible for retry based on per-type limits.
|
|
156
|
+
* RETRY_WAIT makes the waiting period visible in the UI. A separate sweep then promotes
|
|
157
|
+
* RETRY_WAIT → QUEUED once nextRetryAt <= NOW(). */
|
|
148
158
|
export declare function retryEligibleFailedJobs(): Promise<void>;
|
|
149
159
|
/** Promotes FAILED jobs to DLQ if they exceed their per-type retry limits. */
|
|
150
160
|
export declare function promoteToDeadLetterQueue(): Promise<void>;
|
|
@@ -169,7 +179,7 @@ export declare function createTrackedJob(type: string, config: {
|
|
|
169
179
|
[k: string]: any;
|
|
170
180
|
}): Promise<string>;
|
|
171
181
|
/** Mark a tracked job DONE or FAILED. Safe to call in finally — swallows errors.
|
|
172
|
-
*
|
|
182
|
+
* GAP-14/15: Uses failure-type classification for per-type backoff on FAILED. */
|
|
173
183
|
export declare function finishTrackedJob(tenantId: string, jobId: string, error?: string): Promise<void>;
|
|
174
184
|
/** Enqueue a generic platform job — returns the job ID immediately. */
|
|
175
185
|
export declare function enqueueJob(type: string, config: any): Promise<string>;
|
|
@@ -184,8 +194,10 @@ export declare function getJob(tenantId: string, jobId: string): Promise<{
|
|
|
184
194
|
status: string;
|
|
185
195
|
tenantId: string;
|
|
186
196
|
projectId: string;
|
|
197
|
+
inline: boolean;
|
|
187
198
|
config: import("@prisma/client/runtime/library").JsonValue;
|
|
188
199
|
retryCount: number;
|
|
200
|
+
failureType: string | null;
|
|
189
201
|
queuedAt: Date;
|
|
190
202
|
startedAt: Date | null;
|
|
191
203
|
finishedAt: Date | null;
|
|
@@ -199,6 +211,18 @@ export declare function getJob(tenantId: string, jobId: string): Promise<{
|
|
|
199
211
|
nextRetryAt: Date | null;
|
|
200
212
|
dlq: boolean;
|
|
201
213
|
dlqReason: string | null;
|
|
214
|
+
leaseExpiresAt: Date | null;
|
|
215
|
+
fencingToken: string | null;
|
|
216
|
+
checkpoint: import("@prisma/client/runtime/library").JsonValue | null;
|
|
217
|
+
checkpointAt: Date | null;
|
|
218
|
+
parentJobId: string | null;
|
|
219
|
+
rootJobId: string | null;
|
|
220
|
+
currentStep: string | null;
|
|
221
|
+
requeuedAt: Date | null;
|
|
222
|
+
dlqAt: Date | null;
|
|
223
|
+
dlqRedriveCount: number;
|
|
224
|
+
submittedBy: string | null;
|
|
225
|
+
priority: number;
|
|
202
226
|
} | null>;
|
|
203
227
|
/** List recent jobs for a project. */
|
|
204
228
|
export declare function listJobs(tenantId: string, projectId: string): Promise<{
|
|
@@ -211,8 +235,10 @@ export declare function listJobs(tenantId: string, projectId: string): Promise<{
|
|
|
211
235
|
status: string;
|
|
212
236
|
tenantId: string;
|
|
213
237
|
projectId: string;
|
|
238
|
+
inline: boolean;
|
|
214
239
|
config: import("@prisma/client/runtime/library").JsonValue;
|
|
215
240
|
retryCount: number;
|
|
241
|
+
failureType: string | null;
|
|
216
242
|
queuedAt: Date;
|
|
217
243
|
startedAt: Date | null;
|
|
218
244
|
finishedAt: Date | null;
|
|
@@ -226,8 +252,23 @@ export declare function listJobs(tenantId: string, projectId: string): Promise<{
|
|
|
226
252
|
nextRetryAt: Date | null;
|
|
227
253
|
dlq: boolean;
|
|
228
254
|
dlqReason: string | null;
|
|
255
|
+
leaseExpiresAt: Date | null;
|
|
256
|
+
fencingToken: string | null;
|
|
257
|
+
checkpoint: import("@prisma/client/runtime/library").JsonValue | null;
|
|
258
|
+
checkpointAt: Date | null;
|
|
259
|
+
parentJobId: string | null;
|
|
260
|
+
rootJobId: string | null;
|
|
261
|
+
currentStep: string | null;
|
|
262
|
+
requeuedAt: Date | null;
|
|
263
|
+
dlqAt: Date | null;
|
|
264
|
+
dlqRedriveCount: number;
|
|
265
|
+
submittedBy: string | null;
|
|
266
|
+
priority: number;
|
|
229
267
|
}[]>;
|
|
230
|
-
/** Cancel a RUNNING or QUEUED job.
|
|
268
|
+
/** Cancel a RUNNING or QUEUED job.
|
|
269
|
+
* Sets status to CANCEL_REQUESTED (GAP-08) so the worker's abort handler can
|
|
270
|
+
* detect the request and set CANCELLED + finishedAt after the underlying work stops.
|
|
271
|
+
* The in-process AbortController is also triggered for same-process jobs. */
|
|
231
272
|
export declare function cancelJob(tenantId: string, jobId: string): Promise<void>;
|
|
232
273
|
/** Re-enqueue a job using the same config as a previous job. */
|
|
233
274
|
export declare function rerunJob(tenantId: string, jobId: string): Promise<string>;
|