8.2.8 • Published 10 months ago

@nldoc/baseworker v8.2.8

Weekly downloads
-
License
EUPL-1.2
Repository
-
Last release
10 months ago

PDF Processor Base Worker for Typescript

This project migrated to gitlab.com/logius/nldoc/lib/typescript/baseworker.

This repository contains a foundational worker implementation for Typescript projects. The worker handles connections to AMQP, you just have to add a message handler!

How to use

Install this package by running: npm install @nldoc/baseworker

You can now import Worker in your project!

Example

import { logger } from '@nldoc/logger'
import { Worker, WorkerConfig } from '@nldoc/baseworker'

try {
    if (!process.env.EXCHANGE) {
        throw new Error('No exchange prefix defined')
    }

    const config: WorkerConfig = {
        name: 'your-awesome-worker-name',
        amqpHost: process.env.AMQP_HOST ?? 'localhost',
        amqpPass: process.env.AMQP_PASS,
        amqpPort: process.env.AMQP_PORT ?? '5672',
        amqpProtocol: process.env.AMQP_PROTOCOL ?? 'amqp',
        amqpUser: process.env.AMQP_USER,
        exchangePrefix: process.env.EXCHANGE,
        workerInstanceName: process.env.HOSTNAME ?? '',
        prefetchLimit: 10,
    }

    const handler: WorkerMessageHandler = async ({ job, storage }) => {
        // TODO: Get the actual thing you need.
        storage.getFileBuffer({ bucketName: job.bucketName, filePath: job.filePath })

        // TODO: Do the magic your worker does

        return {
            success: true,
            result: 'your amazing result',
            confidence: 100,
        }
    }

    const worker = new Worker({
        logger,
        messageHandler: handler,
        config,
    })

    await worker.start()
} catch (error) {
    if (error instanceof Error) {
        // Do stuff with this error...
    }
    throw error
}
8.2.8

10 months ago

8.2.7

10 months ago

8.2.6

11 months ago

8.2.5

11 months ago

8.2.4

11 months ago

8.2.3

11 months ago

8.2.2

11 months ago

8.2.1

11 months ago

8.2.0

11 months ago

8.1.0

12 months ago

8.0.5

12 months ago

8.0.4

12 months ago

8.0.3

12 months ago