npm

@enschedule/hub
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

worker

Docker

Environment variables

DB_USER DB_HOST DB_PASSWORD DB_DATABASE DB_PORT ENSCHEDULE_API REGISTER_JOBS_SCRIPT API_PORT or default is 8080 API_HOSTNAME or undefined

Usage

Use the image as is:

cat <<EOC > index.js
const { z } = require('zod');

module.exports = async (worker) => {
  worker.registerJob({
      id: 'log-job',
      title: 'Log message',
      dataSchema: z.object({
          message: z.string(),
      }),
      job: async (data, console) => {
          console.log(data.message);
      },
      description: 'Will print the message on the server',
      example: {
          message: 'some message',
      },
  });
}

EOC
docker container run -p 8080:8080 -e API_ENDPOINT=true -v ${PWD}:/enschedule/jobs enschedule:latest

API

Usage

import { Worker } from '@enschedule/worker';
const worker = new Worker({});
void (async () => {
  worker.registerJob({
    id: 'log-job',
    title: 'Log message',
    dataSchema: z.object({
        message: z.string(),
    }),
    job: async (data, console) => {
        console.log(data.message);
    },
    description: 'Will print the message on the server',
    example: {
        message: 'some message',
    },
  });
  await worker.startPolling();
  if (process.env.ENSCHEDULE_API) {
      worker.serve({ port: 8080 }).listern();
  }
})();

Readme

Keywords

none

Package Sidebar

Install

npm i @enschedule/hub

Weekly Downloads

28

Version

1.0.1

License

MIT

Unpacked Size

16.9 kB

Total Files

4

Last publish

Collaborators

  • ricsam