Skip to content

Commit

Permalink
Merge pull request #120 from moleculerjs/configurable-psql
Browse files Browse the repository at this point in the history
v 0.2.0
  • Loading branch information
AndreMaz authored Nov 23, 2022
2 parents 84ecb79 + 3531692 commit 293e8f8
Show file tree
Hide file tree
Showing 8 changed files with 10,274 additions and 10,136 deletions.
67 changes: 67 additions & 0 deletions packages/moleculer-psql-queue/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<a name="0.2.0"></a>

# [0.2.0]

- Change mixin signature.
**Old**

```js
const PsqlQueueService = require("moleculer-psql-queue");
broker.createService({
name: "pub",
mixins: [
PsqlQueueService(
"postgres://postgres:postgres@localhost:5444/task_queue"
// {}, // Optional worker configs. More info: https://github.com/graphile/worker#runneroptions
// {}, // Optional producer configs: More info: https://github.com/graphile/worker#workerutilsoptions
),
],
});
```

**New**

```js
const PsqlQueueService = require("moleculer-psql-queue");
broker.createService({
name: "pub",
mixins: [
PsqlQueueService(
"postgres://postgres:postgres@localhost:5444/task_queue",
// Default opts
{
// Name of the property in service schema.
schemaProperty: "queues",
// Name of the method in Service to create jobs
createJobMethodName: "createJob",
// Name of the property in Service to produce jobs
producerPropertyName: "$producer",
// Name of the property in Service to consume jobs
consumerPropertyName: "$consumer",
// Name of the internal queue that's used to store the job handlers
internalQueueName: "$queue",
// Name of the property in Service settings to register job event handlers
jobEventHandlersSettingsProperty: "jobEventHandlers",
// Optional producer configs: More info: https://github.com/graphile/worker#workerutilsoptions
producerOpts: {},
// Optional worker configs. More info: https://github.com/graphile/worker#runneroptions
queueOpts: {
concurrency: 5,
// Install signal handlers for graceful shutdown on SIGINT, SIGTERM, etc
noHandleSignals: false,
pollInterval: 1000,
},
}
),
],
});
```

- Rename internal methods to avoid with other libs (e.g. `moleculer-bull`).

- `initLogger` -> `initWorkerLogger`
- `tryConnect` -> `tryConnectWorker`
- `connect` -> `connectWorker`

- Bump deps
41 changes: 32 additions & 9 deletions packages/moleculer-psql-queue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Job queue mixin for [graphile-worker](https://github.com/graphile/worker).
# Install

```
$ npm install moleculer-pqsl-queue
$ npm install moleculer-psql-queue
```

# Configuration
Expand All @@ -25,16 +25,39 @@ $ npm install moleculer-pqsl-queue
## Create queue worker service

```js
const PsqlQueueService = require("moleculer-pqsl-queue");
const PsqlQueueService = require("moleculer-psql-queue");

broker.createService({
name: "task-worker",

mixins: [
PsqlQueueService(
"postgres://postgres:postgres@localhost:5444/task_queue"
// {}, // Optional worker configs. More info: https://github.com/graphile/worker#runneroptions
// {}, // Optional producer configs: More info: https://github.com/graphile/worker#workerutilsoptions
"postgres://postgres:postgres@localhost:5444/task_queue",
// Default opts
{
// Name of the property in service schema.
schemaProperty: "queues",
// Name of the method in Service to create jobs
createJobMethodName: "createJob",
// Name of the property in Service to produce jobs
producerPropertyName: "$producer",
// Name of the property in Service to consume jobs
consumerPropertyName: "$consumer",
// Name of the internal queue that's used to store the job handlers
internalQueueName: "$queue",
// Name of the property in Service settings to register job event handlers
jobEventHandlersSettingsProperty: "jobEventHandlers",

// Optional producer configs: More info: https://github.com/graphile/worker#workerutilsoptions
producerOpts: {},
// Optional worker configs. More info: https://github.com/graphile/worker#runneroptions
queueOpts: {
concurrency: 5,
// Install signal handlers for graceful shutdown on SIGINT, SIGTERM, etc
noHandleSignals: false,
pollInterval: 1000,
},
}
),
],

Expand Down Expand Up @@ -70,7 +93,7 @@ broker.createService({
## Customize worker logger

```js
const PsqlQueueService = require("moleculer-pqsl-queue");
const PsqlQueueService = require("moleculer-psql-queue");

broker.createService({
name: "task-worker",
Expand Down Expand Up @@ -107,7 +130,7 @@ broker.createService({
## Listen to queue events

```js
const PsqlQueueService = require("moleculer-pqsl-queue");
const PsqlQueueService = require("moleculer-psql-queue");

broker.createService({
name: "task-worker",
Expand Down Expand Up @@ -147,7 +170,7 @@ broker.createService({
## Create Task

```js
const PsqlQueueService = require("moleculer-pqsl-queue");
const PsqlQueueService = require("moleculer-psql-queue");

broker.createService({
name: "pub",
Expand Down Expand Up @@ -185,7 +208,7 @@ broker.createService({
The graphile-worker lib provides some advanced features like [administration functions](https://github.com/graphile/worker#administration-functions). These functions can be used to manage the queue and can be accessed via the `this.$producer` property of the service.

```js
const PsqlQueueService = require("moleculer-pqsl-queue");
const PsqlQueueService = require("moleculer-psql-queue");

broker.createService({
name: "pub",
Expand Down
26 changes: 25 additions & 1 deletion packages/moleculer-psql-queue/examples/simple/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,31 @@ broker.createService({

mixins: [
PsqlQueueService(
"postgres://postgres:postgres@localhost:5444/task_queue"
"postgres://postgres:postgres@localhost:5444/task_queue",
{
// Name of the property in service schema.
schemaProperty: "queues",
// Name of the method in Service to create jobs
createJobMethodName: "createJob",
// Name of the property in Service to produce jobs
producerPropertyName: "$producer",
// Name of the property in Service to consume jobs
consumerPropertyName: "$consumer",
// Name of the internal queue that's used to store the job handlers
internalQueueName: "$queue",
// Name of the property in Service settings to register job event handlers
jobEventHandlersSettingsProperty: "jobEventHandlers",

// Optional producer configs: More info: https://github.com/graphile/worker#workerutilsoptions
producerOpts: {},
// Optional worker configs. More info: https://github.com/graphile/worker#runneroptions
queueOpts: {
concurrency: 5,
// Install signal handlers for graceful shutdown on SIGINT, SIGTERM, etc
noHandleSignals: false,
pollInterval: 1000,
},
}
),
],

Expand Down
Loading

0 comments on commit 293e8f8

Please sign in to comment.