@noego/captain 1.0.2 → 1.1.1
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/README.md +31 -0
- package/dist/components/cli.d.ts +19 -0
- package/dist/components/executor.d.ts +11 -0
- package/dist/components/parser.d.ts +9 -0
- package/dist/components/scheduler.d.ts +15 -0
- package/dist/container.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/models/task.d.ts +27 -0
- package/dist/scheduler.d.ts +12 -0
- package/dist/scheduler.js +13 -0
- package/package.json +18 -4
package/README.md
CHANGED
|
@@ -174,6 +174,37 @@ Each task supports the following options:
|
|
|
174
174
|
- **Data processing**: Schedule batch processing of data at regular intervals
|
|
175
175
|
- **Service coordination**: Trigger API calls or service interactions on a schedule
|
|
176
176
|
|
|
177
|
+
## Using Captain as a Library
|
|
178
|
+
|
|
179
|
+
Captain's scheduler can be embedded in your own application without starting the CLI. Import from the `@noego/captain/scheduler` entry point — it is side-effect free (no argument parsing, no `.env` loading, no CLI container) and ships with generated TypeScript declarations.
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
import { Scheduler, type TaskDefinition } from '@noego/captain/scheduler';
|
|
183
|
+
import * as winston from 'winston';
|
|
184
|
+
|
|
185
|
+
const logger = winston.createLogger({ transports: [new winston.transports.Console()] });
|
|
186
|
+
const scheduler = new Scheduler(logger);
|
|
187
|
+
|
|
188
|
+
const task: TaskDefinition = { schedule: '*/5 * * * *', description: 'Every five minutes' };
|
|
189
|
+
|
|
190
|
+
scheduler.scheduleTask('heartbeat', task, async () => {
|
|
191
|
+
console.log('tick');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// Later
|
|
195
|
+
scheduler.stopTask('heartbeat');
|
|
196
|
+
scheduler.stopAllTasks();
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
CommonJS works too: `const { Scheduler } = require('@noego/captain/scheduler')`.
|
|
200
|
+
|
|
201
|
+
Exports: `Scheduler`, and the types `TaskDefinition` (alias `CaptainTaskDefinition`), `Config`, `TasksFile`.
|
|
202
|
+
|
|
203
|
+
Do **not** import the package root (`@noego/captain`) as a library — it is the CLI entry and runs `main()` on load. Existing deep imports such as `@noego/captain/dist/components/scheduler` still resolve, but `@noego/captain/scheduler` is the supported path.
|
|
204
|
+
|
|
205
|
+
If you bundle your application (Vite, esbuild, Rollup), externalize Captain including its subpaths, e.g. `/^@noego\/captain(?:\/|$)/`, rather than only the bare package name.
|
|
206
|
+
|
|
207
|
+
|
|
177
208
|
## Developing with Captain
|
|
178
209
|
|
|
179
210
|
For developers who want to modify or extend Captain:
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as winston from 'winston';
|
|
2
|
+
import { Parser } from './parser';
|
|
3
|
+
import { Scheduler } from './scheduler';
|
|
4
|
+
import { Executor } from './executor';
|
|
5
|
+
export declare class CLI {
|
|
6
|
+
private logger;
|
|
7
|
+
private parser;
|
|
8
|
+
private scheduler;
|
|
9
|
+
private executor;
|
|
10
|
+
private program;
|
|
11
|
+
private readonly trace;
|
|
12
|
+
constructor(logger: winston.Logger, parser: Parser, scheduler: Scheduler, executor: Executor);
|
|
13
|
+
setup(): void;
|
|
14
|
+
processFiles(files: string[], options: any): Promise<void>;
|
|
15
|
+
private listTasks;
|
|
16
|
+
private runSingleTask;
|
|
17
|
+
private scheduleTasks;
|
|
18
|
+
parse(argv: string[]): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TaskDefinition } from '../models/task';
|
|
2
|
+
import * as winston from 'winston';
|
|
3
|
+
export declare class Executor {
|
|
4
|
+
private logger;
|
|
5
|
+
private runningTasks;
|
|
6
|
+
private readonly trace;
|
|
7
|
+
constructor(logger: winston.Logger);
|
|
8
|
+
executeTask(taskName: string, taskDef: TaskDefinition): Promise<boolean>;
|
|
9
|
+
private checkConcurrency;
|
|
10
|
+
private removeRunningTask;
|
|
11
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TasksFile } from '../models/task';
|
|
2
|
+
import * as winston from 'winston';
|
|
3
|
+
export declare class Parser {
|
|
4
|
+
private logger;
|
|
5
|
+
private readonly trace;
|
|
6
|
+
constructor(logger: winston.Logger);
|
|
7
|
+
parseFile(filePath: string): Promise<TasksFile>;
|
|
8
|
+
validateTask(taskName: string, task: any): boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TaskDefinition } from '../models/task';
|
|
2
|
+
export interface SchedulerLogger {
|
|
3
|
+
info(message: string): void;
|
|
4
|
+
warn(message: string): void;
|
|
5
|
+
error(message: string): void;
|
|
6
|
+
}
|
|
7
|
+
export declare class Scheduler {
|
|
8
|
+
private logger;
|
|
9
|
+
private schedules;
|
|
10
|
+
private readonly trace;
|
|
11
|
+
constructor(logger: SchedulerLogger);
|
|
12
|
+
scheduleTask(taskName: string, taskDef: TaskDefinition, callback: () => Promise<void>): boolean;
|
|
13
|
+
stopTask(taskName: string): boolean;
|
|
14
|
+
stopAllTasks(): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initializeContainer(): import("@noego/ioc").IContainerClient & import("@noego/ioc").IContainerSetup;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface TaskDefinition {
|
|
2
|
+
description?: string;
|
|
3
|
+
schedule: string;
|
|
4
|
+
file?: string;
|
|
5
|
+
command?: string;
|
|
6
|
+
timeout?: number;
|
|
7
|
+
concurrency?: {
|
|
8
|
+
max?: number;
|
|
9
|
+
allow_overlap?: boolean;
|
|
10
|
+
};
|
|
11
|
+
retry?: {
|
|
12
|
+
attempts?: number;
|
|
13
|
+
backoff?: "fixed" | "exponential";
|
|
14
|
+
delay?: number;
|
|
15
|
+
};
|
|
16
|
+
env?: Record<string, string>;
|
|
17
|
+
}
|
|
18
|
+
export interface Config {
|
|
19
|
+
default_timeout?: number;
|
|
20
|
+
max_concurrency?: number;
|
|
21
|
+
timezone?: string;
|
|
22
|
+
log_level?: "debug" | "info" | "warn" | "error";
|
|
23
|
+
}
|
|
24
|
+
export interface TasksFile {
|
|
25
|
+
tasks: Record<string, TaskDefinition>;
|
|
26
|
+
config?: Config;
|
|
27
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public, side-effect-free library entry point for the Captain scheduler.
|
|
3
|
+
*
|
|
4
|
+
* Importing this module never starts the CLI, parses process arguments,
|
|
5
|
+
* loads environment files, or initializes the CLI IoC container.
|
|
6
|
+
*
|
|
7
|
+
* import { Scheduler } from '@noego/captain/scheduler';
|
|
8
|
+
*/
|
|
9
|
+
export { Scheduler } from './components/scheduler';
|
|
10
|
+
export type { TaskDefinition, Config, TasksFile } from './models/task';
|
|
11
|
+
/** Alias of {@link TaskDefinition} for consumers that prefer a namespaced name. */
|
|
12
|
+
export type { TaskDefinition as CaptainTaskDefinition } from './models/task';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Scheduler = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Public, side-effect-free library entry point for the Captain scheduler.
|
|
6
|
+
*
|
|
7
|
+
* Importing this module never starts the CLI, parses process arguments,
|
|
8
|
+
* loads environment files, or initializes the CLI IoC container.
|
|
9
|
+
*
|
|
10
|
+
* import { Scheduler } from '@noego/captain/scheduler';
|
|
11
|
+
*/
|
|
12
|
+
var scheduler_1 = require("./components/scheduler");
|
|
13
|
+
Object.defineProperty(exports, "Scheduler", { enumerable: true, get: function () { return scheduler_1.Scheduler; } });
|
package/package.json
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noego/captain",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "YAML-driven task runner for TypeScript files",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./scheduler": {
|
|
13
|
+
"types": "./dist/scheduler.d.ts",
|
|
14
|
+
"default": "./dist/scheduler.js"
|
|
15
|
+
},
|
|
16
|
+
"./dist/*": "./dist/*.js",
|
|
17
|
+
"./package.json": "./package.json",
|
|
18
|
+
"./dist/*.js": "./dist/*.js"
|
|
19
|
+
},
|
|
6
20
|
"bin": {
|
|
7
|
-
"captain": "
|
|
21
|
+
"captain": "bin/captain.js"
|
|
8
22
|
},
|
|
9
23
|
"files": [
|
|
10
24
|
"dist",
|
|
@@ -35,8 +49,8 @@
|
|
|
35
49
|
"access": "public"
|
|
36
50
|
},
|
|
37
51
|
"dependencies": {
|
|
38
|
-
"@noego/ioc": "^0.
|
|
39
|
-
"@noego/trace": "^0.0
|
|
52
|
+
"@noego/ioc": "^0.8.0",
|
|
53
|
+
"@noego/trace": "^0.2.0",
|
|
40
54
|
"commander": "^13.1.0",
|
|
41
55
|
"dotenv": "^16.5.0",
|
|
42
56
|
"js-yaml": "^4.1.0",
|