Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
test
coverage
.git/
.github/
.husky/
test/
.*rc
*.config.js
tsconfig.json
.nyc_output/
coverage/
node_modules/
.npm
.eslintcache
.env
.DS_Store
npm-debug.log*
yarn-debug.log*
yarn-error.log*
83 changes: 83 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { EventEmitter } from "events";

export = SBS;

declare class SBS extends EventEmitter {
constructor(opt?: SBS.Options);

maxConcurrent: number;
exec: SBS.ExecFunction | null;
retry: boolean | SBS.RetryFunction;
retryLater: boolean;
maxRetry: number | null;
retryDelay: number;
interval: number;
noAutoClear: boolean;
name: string;
submitHook: SBS.SubmitHookFunction | null;
queue: SBS.Queue<SBS.Job>;
failed: Map<string, Error>;
finished: Map<string, any>;
running: Set<string>;
waiting: Map<string, Array<{ resolve: (value?: any) => void, reject: (reason?: any) => void, keepResults: boolean }>>;

qsub(job: SBS.Job | SBS.ExecFunction | any, urgent?: boolean): string | null | Promise<string | null>;
qdel(id: string): boolean;
qstat(id: string): "finished" | "failed" | "waiting" | "running" | "removed" | null;
getResult(id: string, keepResult?: boolean): any;
qwait(id: string, keepResult?: boolean): Promise<any>;
qsubAndWait(job: SBS.Job | SBS.ExecFunction | any, keepResult?: boolean): Promise<any>;
qwaitAll(ids: string[], keepResult?: boolean): Promise<any[]>;
start(): void;
stop(): void;
size(): number;
getRunning(): string[];
clear(): void;
clearResults(): void;
}

declare namespace SBS {
export interface Options {
exec?: ExecFunction;
maxConcurrent?: number;
retry?: boolean | RetryFunction;
retryLater?: boolean;
maxRetry?: number;
retryDelay?: number;
interval?: number;
name?: string;
submitHook?: SubmitHookFunction;
noAutoStart?: boolean;
noAutoClear?: boolean;
}

export type ExecFunction = (...args: any[]) => any | Promise<any>;
export type RetryFunction = (err: Error) => boolean | Promise<boolean>;
export type SubmitHookFunction = (queue: Queue<Job>, job: Job | ExecFunction | any, urgent: boolean) => boolean | Promise<boolean>;

export interface Job {
exec?: ExecFunction;
args?: any;
maxRetry?: number;
retryDelay?: number;
forceRetry?: boolean;
retry?: boolean | RetryFunction;
retryLater?: boolean;
name?: string;
id?: string;
retryCount?: number;
}

export class Queue<T> {
constructor();
enqueue(element: T, urgent?: boolean, id?: string): string;
dequeue(): [T | null, string | null];
del(id: string): boolean;
clear(): void;
size(): number;
has(id: string): boolean;
getLastEntry(needLastExecuted?: boolean): T | null;
find(cb: (element: T) => boolean): T | null;
removeFromQueue(entries: T[]): void;
}
}
16 changes: 12 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "simple batch system provides job schduler like async function queueing system.",
"type": "module",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"repository": "github:so5/sbs",
"scripts": {
"mocha": "mocha \"test/**/*.js\"",
Expand Down Expand Up @@ -42,7 +43,8 @@
"mocha": "10.8.2",
"mocha-lcov-reporter": "^1.3.0",
"semantic-release": "^24.2.7",
"sinon": "15.2.0"
"sinon": "15.2.0",
"typescript": "^5.9.3"
},
"dependencies": {
"debug": "^4.3.4",
Expand Down
10 changes: 10 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"allowJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "lib"
},
"include": ["lib/**/*.js"],
"exclude": ["node_modules"]
}