Skip to the content.

Table of contents

  1. Getting started
  2. What’s a Job/Batch/Pipeline
  3. Running the server
  4. Creating a worker
  5. The GNJ API
  6. Plugin the server to your express
  7. Q&A
  8. Contributing

You can create your workers from scratch using the Graphql schema. Or you can use the few utilities functions available to quickly setup a worker.


checkForJobs()

// Create an ApolloClient that uses your endpoint url
// Here it is using the default url provided by the out-of-the-box server
import {ApolloClient} from "@apollo/client";

const client = New ApolloClient({uri : 'http://localhost:8080/graphql'})

const job = await checkForJobs({
  typeList: ['myJobType'],
  client,
  processingFunction: async (job) => {
    const result = await myApiCall()
    return myProcessingFunction(result)
  }
})

When processingFunction return something, the job is considered as done. The returned Object is serialized and stored as the “output” of the job.


Easy debug without looping

With the looping option to false the worker will only check for a job once. Made for end-to-end tests or manual debugging.

const job = await checkForJobs({
...,
processingFunction: ...,
looping: false
})

Facilities


updateProcessingInfo()

const job = await checkForJobs({
  typeList: ["myJobType"],
  client,
  processingFunction: async (job, { updateProcessingInfo }) => {
    await updateProcessingInfo({ percent: 10 });
  },
  looping: false,
});

Avoiding spamming your API

Some jobs runs very rarely, so you may want that your worker only check the queue from time to time.

const job = await checkForJobs({
...,
processingFunction: ...,
loopTime: 60 \* 1000 // Every minute
})

Identifying workers

GNJ automatically generated uuid for your new workers to easily track what went wrong. But if you need to link a run to an id your want you can just specify it under the workerId property.

const job = await checkForJobs({
...,
processingFunction: ...,
workerId: 'manualCallPreMigration'
})

They all use the GraphQL api provided by the server. So even if it’s really convenient to use those functions you can create your own.


Previous: Running the server

Next: The GNJ API


Teamstarter’s other libraries