@supergrowthai/tq 1.0.1-canary.a2ffe03

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.
@@ -0,0 +1,19 @@
1
+ import { IAsyncTaskManager, IMessageQueue, ProcessedTaskResult, Processor, QueueName } from '@supergrowthai/mq';
2
+ import { CronTask } from '../adapters/index.js';
3
+ declare function addTasks(messageQueue: IMessageQueue, tasks: CronTask<any>[]): Promise<void>;
4
+ declare function postProcessTasks(messageQueue: IMessageQueue, { failedTasks: failedTasksRaw, newTasks, successTasks }: ProcessedTaskResult): Promise<void>;
5
+ declare function startConsumingTasks(messageQueue: IMessageQueue, streamName: QueueName): Promise<void>;
6
+ declare function processMatureTasks(messageQueue: IMessageQueue): void;
7
+ declare function taskProcessServer(messageQueue: IMessageQueue): void;
8
+ declare function processBatch(messageQueue: IMessageQueue, queueId: QueueName, processor: Processor, limit?: number): Promise<ProcessedTaskResult>;
9
+ declare function setAsyncTaskManager(manager: IAsyncTaskManager): void;
10
+ declare const _default: {
11
+ processBatch: typeof processBatch;
12
+ processMatureTasks: typeof processMatureTasks;
13
+ startConsumingTasks: typeof startConsumingTasks;
14
+ postProcessTasks: typeof postProcessTasks;
15
+ addTasks: typeof addTasks;
16
+ taskProcessServer: typeof taskProcessServer;
17
+ setAsyncTaskManager: typeof setAsyncTaskManager;
18
+ };
19
+ export default _default;
@@ -0,0 +1,19 @@
1
+ import { ActionResults } from './actions/Actions.js';
2
+ import { AsyncActions } from './actions/AsyncActions.js';
3
+ import { CronTask } from '../adapters/index.js';
4
+ import { IAsyncTaskManager, IMessageQueue } from '@supergrowthai/mq';
5
+ /**
6
+ * Runs tasks either from a provided array or by fetching them based on task types
7
+ * @param taskRunnerId - Unique identifier for this run
8
+ * @param tasksRaw - Either an array of tasks to process or an array of task types to fetch
9
+ * @returns Results of task processing
10
+ */
11
+ export interface AsyncTask {
12
+ task: CronTask<any>;
13
+ promise: Promise<void>;
14
+ startTime: number;
15
+ actions: AsyncActions;
16
+ }
17
+ export default function taskRunner(messageQueue: IMessageQueue, taskRunnerId: string, tasksRaw: Array<CronTask<any>>, asyncTaskManager?: IAsyncTaskManager): Promise<ActionResults & {
18
+ asyncTasks: AsyncTask[];
19
+ }>;
@@ -0,0 +1,74 @@
1
+ import { CronTask } from '../adapters/index.js';
2
+ import { ObjectId } from 'mongodb';
3
+ /**
4
+ * Adds multiple tasks to the scheduled queue
5
+ */
6
+ declare function addTasksToScheduled(tasks: CronTask<any>[]): Promise<any>;
7
+ /**
8
+ * Gets mature tasks that are ready to be processed
9
+ * Implements a two-phase approach:
10
+ * 1. Reset stale processing tasks
11
+ * 2. Fetch and mark new mature tasks
12
+ */
13
+ declare function getMatureTasks(timestamp: number): Promise<CronTask<any>[]>;
14
+ /**
15
+ * Marks tasks as processing with current timestamp
16
+ */
17
+ declare function markTasksAsProcessing(taskIds: ObjectId[]): Promise<void>;
18
+ /**
19
+ * Marks tasks as executed/completed
20
+ */
21
+ declare function markTasksAsExecuted(taskIds: ObjectId[]): Promise<void>;
22
+ /**
23
+ * Marks tasks as failed and increments retry count
24
+ */
25
+ declare function markTasksAsFailed(taskIds: ObjectId[]): Promise<void>;
26
+ /**
27
+ * Updates multiple tasks with specific updates
28
+ */
29
+ declare function updateTasks(updates: Array<{
30
+ id: ObjectId;
31
+ updates: Partial<CronTask<any>>;
32
+ }>): Promise<void>;
33
+ /**
34
+ * Gets tasks by their IDs
35
+ */
36
+ declare function getTasksByIds(taskIds: ObjectId[]): Promise<CronTask<any>[]>;
37
+ /**
38
+ * Gets cleanup statistics
39
+ */
40
+ declare function getCleanupStats(): Promise<{
41
+ orphanedTasks: number;
42
+ expiredTasks: number;
43
+ }>;
44
+ /**
45
+ * Cleans up orphaned and expired tasks
46
+ */
47
+ declare function cleanupTasks(): Promise<void>;
48
+ /**
49
+ * Updates tasks for retry with new execution time and retry count
50
+ */
51
+ declare function updateTasksForRetry(tasks: CronTask<any>[]): Promise<void>;
52
+ /**
53
+ * Marks tasks as successful/completed
54
+ */
55
+ declare function markTasksAsSuccess(tasks: CronTask<any>[]): Promise<void>;
56
+ /**
57
+ * Marks tasks as ignored (same as failed for now)
58
+ */
59
+ declare function markTasksAsIgnored(tasks: CronTask<any>[]): Promise<void>;
60
+ declare const TaskStore: {
61
+ addTasksToScheduled: typeof addTasksToScheduled;
62
+ getMatureTasks: typeof getMatureTasks;
63
+ markTasksAsProcessing: typeof markTasksAsProcessing;
64
+ markTasksAsExecuted: typeof markTasksAsExecuted;
65
+ markTasksAsFailed: typeof markTasksAsFailed;
66
+ updateTasks: typeof updateTasks;
67
+ getTasksByIds: typeof getTasksByIds;
68
+ getCleanupStats: typeof getCleanupStats;
69
+ cleanupTasks: typeof cleanupTasks;
70
+ updateTasksForRetry: typeof updateTasksForRetry;
71
+ markTasksAsSuccess: typeof markTasksAsSuccess;
72
+ markTasksAsIgnored: typeof markTasksAsIgnored;
73
+ };
74
+ export default TaskStore;
@@ -0,0 +1,46 @@
1
+ import { IMessageQueue, QueueName } from '@supergrowthai/mq';
2
+ import { TaskExecutor } from './core/base/interfaces.js';
3
+ export * from './types.js';
4
+ export * from './adapters/index.js';
5
+ export { default as TaskStore } from './core/task-store.js';
6
+ export { default as taskHandler } from './core/task-handler.js';
7
+ export { default as taskRunner } from './core/task-runner.js';
8
+ export { getEnabledQueues } from './core/environment.js';
9
+ export { Actions } from './core/actions/Actions.js';
10
+ export { AsyncActions } from './core/actions/AsyncActions.js';
11
+ export { AsyncTaskManager } from './core/async/AsyncTaskManager.js';
12
+ export * from './core/base/interfaces.js';
13
+ export * from './task-registry.js';
14
+ export { default as tId } from './utils/task-id-gen.js';
15
+ declare class TaskQueue {
16
+ queueTaskExecutorMap: Map<QueueName, Map<string, TaskExecutor<any>>>;
17
+ /**
18
+ * Registers a task executor with a message queue and queue name
19
+ * @param messageQueue The message queue to register with
20
+ * @param queueName The name of the queue
21
+ * @param taskType The type of task
22
+ * @param executor The executor for the task
23
+ */
24
+ register(messageQueue: IMessageQueue, queueName: QueueName, taskType: string, executor: TaskExecutor<any>): void;
25
+ /**
26
+ * Gets the task executor for a specific queue and task type
27
+ * @param queueName The name of the queue
28
+ * @param taskType The type of task
29
+ * @returns The executor for the task
30
+ */
31
+ getExecutor(queueName: QueueName, taskType: string): TaskExecutor<any> | undefined;
32
+ /**
33
+ * Gets all registered queues
34
+ * @returns Array of queue names
35
+ */
36
+ getQueues(): QueueName[];
37
+ /**
38
+ * Gets all task types for a specific queue
39
+ * @param queueName The name of the queue
40
+ * @returns Array of task types
41
+ */
42
+ getTasksForQueue(queueName: QueueName): string[];
43
+ }
44
+ declare const taskQueue: TaskQueue;
45
+ export { TaskQueue };
46
+ export default taskQueue;
@@ -0,0 +1,4 @@
1
+ type TasksTypeExt = string;
2
+ export type TasksType = TasksTypeExt;
3
+ declare const _default: {};
4
+ export default _default;
@@ -0,0 +1,2 @@
1
+ export declare enum CronTaskType {
2
+ }
@@ -0,0 +1,3 @@
1
+ import { CronTask } from '../adapters';
2
+ declare function tId<T>(task: CronTask<T>): any;
3
+ export default tId;
@@ -0,0 +1,2 @@
1
+ export * from './src/types'
2
+ export {}
package/dist/types.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ var CronTaskType = /* @__PURE__ */ ((CronTaskType2) => {
4
+ return CronTaskType2;
5
+ })(CronTaskType || {});
6
+ exports.CronTaskType = CronTaskType;
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sources":["../src/types.ts"],"sourcesContent":["export enum CronTaskType {}"],"names":["CronTaskType"],"mappings":";;AAAO,IAAK,iCAAAA,kBAAL;AAAK,SAAAA;AAAA,GAAA,gBAAA,CAAA,CAAA;;"}
package/dist/types.mjs ADDED
@@ -0,0 +1,7 @@
1
+ var CronTaskType = /* @__PURE__ */ ((CronTaskType2) => {
2
+ return CronTaskType2;
3
+ })(CronTaskType || {});
4
+ export {
5
+ CronTaskType
6
+ };
7
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","sources":["../src/types.ts"],"sourcesContent":["export enum CronTaskType {}"],"names":["CronTaskType"],"mappings":"AAAO,IAAK,iCAAAA,kBAAL;AAAK,SAAAA;AAAA,GAAA,gBAAA,CAAA,CAAA;"}
package/package.json ADDED
@@ -0,0 +1,101 @@
1
+ {
2
+ "name": "@supergrowthai/tq",
3
+ "version": "1.0.1-canary.a2ffe03",
4
+ "description": "Task queue management library with multiple executor types and async task handling",
5
+ "repository": "https://github.com/captadexp/next-blog",
6
+ "homepage": "https://github.com/captadexp/next-blog/tree/main#readme",
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.mjs",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.mjs",
15
+ "require": "./dist/index.js"
16
+ },
17
+ "./types": {
18
+ "types": "./dist/types.d.ts",
19
+ "import": "./dist/types.mjs",
20
+ "require": "./dist/types.js"
21
+ },
22
+ "./adapters": {
23
+ "types": "./dist/adapters/index.d.ts",
24
+ "import": "./dist/adapters/index.mjs",
25
+ "require": "./dist/adapters/index.js"
26
+ },
27
+ "./adapters/database": {
28
+ "types": "./dist/adapters/database-adapter.d.ts",
29
+ "import": "./dist/adapters/database-adapter.mjs",
30
+ "require": "./dist/adapters/database-adapter.js"
31
+ },
32
+ "./core/base/interfaces": {
33
+ "types": "./dist/core/base/interfaces.d.ts",
34
+ "import": "./dist/core/base/interfaces.mjs",
35
+ "require": "./dist/core/base/interfaces.js"
36
+ },
37
+ "./core/task-store": {
38
+ "types": "./dist/core/task-store.d.ts",
39
+ "import": "./dist/core/task-store.mjs",
40
+ "require": "./dist/core/task-store.js"
41
+ },
42
+ "./core/task-handler": {
43
+ "types": "./dist/core/task-handler.d.ts",
44
+ "import": "./dist/core/task-handler.mjs",
45
+ "require": "./dist/core/task-handler.js"
46
+ },
47
+ "./core/task-runner": {
48
+ "types": "./dist/core/task-runner.d.ts",
49
+ "import": "./dist/core/task-runner.mjs",
50
+ "require": "./dist/core/task-runner.js"
51
+ },
52
+ "./core/actions": {
53
+ "types": "./dist/core/actions/Actions.d.ts",
54
+ "import": "./dist/core/actions/Actions.mjs",
55
+ "require": "./dist/core/actions/Actions.js"
56
+ },
57
+ "./core/actions/async": {
58
+ "types": "./dist/core/actions/AsyncActions.d.ts",
59
+ "import": "./dist/core/actions/AsyncActions.mjs",
60
+ "require": "./dist/core/actions/AsyncActions.js"
61
+ },
62
+ "./core/async": {
63
+ "types": "./dist/core/async/AsyncTaskManager.d.ts",
64
+ "import": "./dist/core/async/AsyncTaskManager.mjs",
65
+ "require": "./dist/core/async/AsyncTaskManager.js"
66
+ },
67
+ "./utils": {
68
+ "types": "./dist/utils/task-id-gen.d.ts",
69
+ "import": "./dist/utils/task-id-gen.mjs",
70
+ "require": "./dist/utils/task-id-gen.js"
71
+ }
72
+ },
73
+ "scripts": {
74
+ "clean": "rm -rf dist",
75
+ "dev": "vite build --watch",
76
+ "build": "vite build",
77
+ "typecheck": "tsc --noEmit",
78
+ "prepublishOnly": "npm run build"
79
+ },
80
+ "files": [
81
+ "dist"
82
+ ],
83
+ "author": "Capt ADExp <tech@developer.toys>",
84
+ "license": "MIT",
85
+ "dependencies": {
86
+ "lodash": "^4.17.21",
87
+ "mongodb": "^6.16.0",
88
+ "moment": "^2.30.1",
89
+ "@supergrowthai/mq": "1.0.1-canary.a2ffe03",
90
+ "@supergrowthai/utils": "1.0.1"
91
+ },
92
+ "devDependencies": {
93
+ "@types/node": "^24.5.2",
94
+ "typescript": "^5.9.2",
95
+ "vite": "^7.1.5",
96
+ "vite-plugin-dts": "^4.5.4"
97
+ },
98
+ "publishConfig": {
99
+ "access": "public"
100
+ }
101
+ }