npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tshio/scheduler-client

v0.0.2

Published

RAD Scheduler Client

Downloads

3

Readme

RAD Scheduler Client

npm version

Non-blocking RAD Scheduler client for Node.js.

This is a 100% JavaScript library, with TypeScript definition, with the Promise API.

This module makes it simple to implement a Node.js application that uses RAD Scheduler.

Table of Contents

Installing

$ npm install @tshio/scheduler-client

or

$ yarn add @tshio/scheduler-client

Loading and configuration module

// CommonJS
const { SchedulerClient } = require('@tshio/scheduler-client');

// ES Module
import { SchedulerClient } from '@tshio/scheduler-client';


const options = {
  host: "localhost",
  port: "50070",
}

const schedulerClient = new SchedulerClient(options);

Examples

const SchedulerClient = require('@tshio/scheduler-client');

const schedulerClient = new SchedulerClient({
    host: "localhost",
    port: 50070,
  });

(async () => {
    
    // Add job
    
    const job = {
      name: "JobExample",
      type: "http",
      payload: {
        url: "example.com",
      },
    };

    const { id } = await schedulerClient.jobs.addJob(job).catch();
  
    // Get jobs
   
    const jobsQueryFilter = {};
    
    const jobs = await schedulerClient.jobs.getJobs(jobsQueryFilter);

    // Cancel job
    
    await schedulerClient.jobs.cancelJob({ jobId: id });
})();

API

schedulerClient.jobs.addJob({ name, type, payload?, jobOptions? }) => Promise<{ id }>

Schedule an action to another service - either to run immediately, at some specific timestamp or as a cron job.

Returns an object

{
  id: string; // job id
}

or throw HttpError

Parameters

| Name | Type | Description | Default | |--------------|------------|---------------------------------------|-----| | name | string | Job name | | | type | string | Job type (always "http") | | | payload | object | Job payload | | | payload.method | string | optional HTTP method, allowed values: GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH | | | payload.url | string | Request URL string | | | payload.headers | object | optional Request headers, example: { "Content-Type": "application/json" } | | | payload.body | object string | optional Request body, string or any of object | | | payload.options | object | optional Request options | | | payload.compress | boolean | optional Support gzip/deflate content encoding. false to disable | false | | payload.follow | number | optional Maximum redirect count. 0 to not follow redirect | 20 | | payload.size | number | optional Maximum response body size in bytes. 0 to disable | 0 | | payload.timeout | number | optional Request/response timeout in ms, it resets on redirect. 0 to disable (OS limit applies) | 0 | | jobOptions | object | optional Job configuration object | | | jobOptions.priority | number | optional Optional priority value. ranges from 1 (highest priority) to MAX_INT (lowest priority). Note that using priorities has a slight impact on performance, so do not use it if not required. | | | jobOptions.delay | number | optional An amount of milliseconds to wait until this job can be processed. Note that for accurate delays, both server and clients should have their clocks synchronized. | | | jobOptions.attempts | number | optional The total number of attempts to try the job until it completes. | 3 | | jobOptions.cron | string | optional Repeat job according to a cron specification. | | | jobOptions.cronStartDate | string | optional Start date when the repeat job should start repeating. Example: "2020-01-01 10:00:00" | | | jobOptions.cronEndDate | string | optional End date when the repeat job should stop repeating. Example: "2020-01-02 15:30:00" | | | jobOptions.cronTimeZone | string | optional Cron Timezone | | | jobOptions.cronLimit | number | optional Number of times the job should repeat at max. | | | jobOptions.backoff | number | optional Setting for automatic retries if the job fails. | 5000 | | jobOptions.lifo | boolean | optional If true, adds the job to the right of the queue instead of the left. | false | | jobOptions.timeout | number | optional The number of milliseconds after which the job should be fail with a timeout error. | | | jobOptions.removeOnComplete | boolean | optional If true, removes the job when it successfully completes. | | | jobOptions.removeOnFail | boolean | optional If true, removes the job when it fails after all attempts. | | | jobOptions.stackTraceLimit | number | optional Limits the amount of stack trace lines that will be recorded in the stacktrace. | |

Back to API

schedulerClient.jobs.getJobs( queryFilter? ) => Promise< object >

Get jobs list (if no query parameters it returns first 25 jobs ordered by name)

Returns an object

{
  jobs: Job[];
  page: number;
  limit: number;
  total: number;
}
interface Job {
  id: string;
  name: string;
  type: JobType;
  cron?: string;
  status: JobStatus;
  jobOptions?: JobOptions;
  payload?: jsonB;
  createdAt: Date;
  updatedAt: Date;
}

or throw HttpError

Parameters

| Name | Type | Description | Default | |--------------|------------|---------------------------------------|-----| | queryFilter | object | optionalQuery filter | | | queryFilter.page | number | optionalPage number | 1 | | queryFilter.limit | number | optionalResponse limit | 25 | | queryFilter.filter | number | optionalFilter object | | | queryFilter.query | number | optionalQuery object | |

Filters can be used search for a single condition or they can be wrapped in logical operands AND and OR. Filtering can be a simple conditional evaluation of a single field.

//
export type GetJobsColumns = "id" | "name" | "status" | "createdAt" | "updatedAt";

export type GetJobsFilterOperators =
  | "eq"
  | "eqOr"
  | "neq"
  | "neqOr"
  | "lt"
  | "ltOr"
  | "lte"
  | "lteOr"
  | "gt"
  | "gtOr"
  | "gte"
  | "gteOr"
  | "include"
  | "includeOr"
  | "in"
  | "inOr";

export interface JobsQueryFilter {
  page?: number;
  limit?: number;
  filter?: {
    [column in GetJobsColumns]?: {
      [operator in GetJobsFilterOperators]?: string;
    };
  };
  order?: {
    by: "id" | "name" | "status" | "createdAt" | "updatedAt";
    type: "asc" | "desc";
  };
}
  • filter[column][operator] = value

    | Name | Type | Description | |-----------------------|------------|----------------------------------------------------------| | column | string | Column name | | operator | string | Operator name | | value | string or number or boolean (depending on the column type) | |

    Examples

    Single parameter filter

    filter: {
      name: {
        include: "job"
      }
    }

    Two parameter filter

    filter: {
      name: {
        include: "job"
      },
      status: {
        eq: "active",
      },
    }
  • order

    | Name | Type | Description | Default | |-----------------------|------------|---------------------------------------------------------------------------------|---------| | by | string | optional column name for order sorting, allowed values: "id", "name", "status", "createdAt", "updatedAt" | id | | type | asc or desc| optional Ascending or descending order | asc |

    Examples

    order: {
      by: "name",
      type: "desc"
    }

Back to API

schedulerClient.jobs.cancelJob({ jobId }) => Promise< void >

Cancels a job with given id

Returns void or throw HttpError

Parameters

| Name | Type | Description | |--------------|------------|---------------------------------------| | jobId | string | Job ID |

Back to API

License

license

This project is licensed under the terms of the MIT license.

About us:

The Software House