@roit/roit-queues
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

ROIT Queues

Usage for Pub/Sub

In the env.yaml file add the pubSubCredential{} and projectId attributes, with the number of folders inside the {}:

dev:
    pubSubCredential{5}: my-credential.json
    projectId: my-project-id

Note: if you use glcloud auth application-default login, you don't need to set pubSubCredential at env file!

Inject in your desired class:

import { PubSubHandler } from '@roit/roit-queues'

constructor( 
    private readonly pubSubHandler: PubSubHandler
) {}

Use the publish method:

const myObject = {
    // properties
}

const messageId = await this.pubSubHandler.publish(myObject, 'myTopic')
console.log(messageId) // outputs 234786275

Usage for Cloud Tasks

In the env.yaml file add the cloudTaskCredencial{} and projectId attributes, with the number of folders inside the {}:

dev:
    cloudTaskCredential{5}: my-credential.json
    projectId: my-project-id

Inject in your desired class:

import { CloudTaskProvider } from '@roit/roit-queues'

constructor( 
    private readonly cloudTaskProvider: CloudTaskProvider
) {}

Schedule Time params:

scheduleTime: {
    seconds?: number
    nanos?: number
    dateExecute?: string // Use moment formats: https://www.npmjs.com/package/moment
    executeAt?: string // Use ms formats: https://www.npmjs.com/package/ms
}

Use the createTask method:

import { TaskConfiguration } from '@roit/roit-queues'

const myTask: TaskConfiguration = {
    url: 'https://endpoint.com',
    httpMethod: 'POST',
    region: 'us-central1',
    queue: 'my-queue',
    scheduleTime: {
        seconds: 3600   
    },
    headers: MyHeadersObject,
    body: MyPayloadObject
}

const taskResponse = await this.cloudTaskProvider.createTask(myTask)
console.log(taskResponse)

Package Sidebar

Install

npm i @roit/roit-queues

Weekly Downloads

420

Version

1.0.4

License

none

Unpacked Size

81.5 kB

Total Files

35

Last publish

Collaborators

  • williampaulo
  • lucasmoreira
  • roitjoaovitor
  • jeremias.silva
  • karlaugust1
  • yucky4
  • tiagodev
  • jenkins.roit
  • tiago.gois
  • evelin.iurko.roit