Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/roitinnovation/roit-queues

Queue manager for Typescript, as well as Nestjs.
https://github.com/roitinnovation/roit-queues

cloudtasks nestjs nodejs pubsub queue typescript

Last synced: about 1 month ago
JSON representation

Queue manager for Typescript, as well as Nestjs.

Awesome Lists containing this project

README

        

# ROIT Queues

### Usage for Pub/Sub

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

```yaml
dev:
pubSubCredential{5}: my-credential.json
firestore:
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:
```typescript
import { PubSubHandler } from '@roit/roit-queues'

constructor(
private readonly pubSubHandler: PubSubHandler
) {}
```

Use the `publish` method:
```typescript
const myObject = {
// properties
}

const attributes = {
// properties
}

const messageId = await this.pubSubHandler.publish(myObject, 'myTopic', attributes)
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 {}:

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

Inject in your desired class:
```typescript
import { CloudTaskProvider } from '@roit/roit-queues'

constructor(
private readonly cloudTaskProvider: CloudTaskProvider
) {}
```

Schedule Time params:
```typescript
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:
```typescript
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)
```