Light Croncile node client with full TypeScript support
- Fully typed api client for Cronicle
- No dependencies (you need to install your own
request-promise
library) - Helper methods to build Timing objects for scheduling events
- Type safety extendable for Categories, Plugins and Targets
npm install cronicle-client
--NOTICE--
request-promise
is a peer dependency and must be installed by you (>=1.0.0)
--NOTICE--
If you want to use the timing objects helpers, you must also install moment
import { CronicleClient, NumberedBoolean, BaseCategories, BaseTargets, getUtcTiming,
HttpPluginMethods, } from 'cronicle-client';
const scheduler = new CronicleClient({
masterUrl: 'http://localhost:3012',
apiKey: '<your api key>',
});
scheduler.createEvent({
plugin: 'urlplug',
title: 'test event1',
enabled: NumberedBoolean.TRUE,
category: BaseCategories.GENERAL,
target: BaseTargets.GENERAL,
timing: getUtcTiming('2016-05-26T14:50:50.900Z'),
timezone: 'Etc/UTC',
params: {
method: HttpPluginMethods.POST,
timeout: '60',
headers: 'Content-Type: application/json',
data: JSON.stringify({ a: 1 }),
url: 'https://requestbin.com',
},
})
.then((data) => {
console.log(`Created event with id: ${data.id}`);
return scheduler.runEvent({ id: data.id });
})
.then((data) => {
console.log(`Started event with job id: ${data.ids[0]}`);
});
import { CronicleClient, IHttpPluginData, IShellPluginData, ITestPluginData, NumberedBoolean,
getUtcTiming } from 'cronicle-client';
export interface ICustomPluginData {
duration: string;
action: string;
}
export interface Plugins {
// Default plugins
urlplug: IHttpPluginData;
shellplug: IShellPluginData;
testplug: ITestPluginData;
// Custom plugins
mycustomplug: ICustomPluginData;
}
export enum Categories {
// Default category
GENERAL = 'general',
// Custom categories...
TEST_CATEGORY = 'cjw6g085901',
TEST_CATEGORY2 = 'cjw6l8mnb02',
}
export enum Targets {
// Default targets...
ALL = 'allgrp',
MAIN = 'maingrp',
// Custom targets...
AWS = 'awsgrp',
GCP = 'gcpgrp',
}
const scheduler = new CronicleClient<Categories, Targets, Plugins>({
masterUrl: 'http://localhost:3012',
apiKey: '<your api key>',
});
scheduler.createEvent({
plugin: 'mycustomplug',
title: 'test event1',
enabled: NumberedBoolean.TRUE,
category: Categories.TEST_CATEGORY2,
target: Targets.AWS,
timing: getUtcTiming('2016-05-26T14:50:50.900Z'),
timezone: 'Etc/UTC',
params: {
duration: '60',
action: JSON.stringify({ a: 1 }),
},
})
.then((data) => {
console.log(`Created event with id: ${data.id}`);
return scheduler.runEvent({ id: data.id });
})
.then((data) => {
console.log(`Started event with job id: ${data.ids[0]}`);
});
TBD
Cronicle client supports Node 6 LTS and higher.
All contributions are happily welcomed!
Please make all pull requests to the master
branch from your fork and ensure tests pass locally.