diff --git a/docs/api/message.md b/docs/api/message.md index ab14d73f..7fa2cb9b 100644 --- a/docs/api/message.md +++ b/docs/api/message.md @@ -23,10 +23,10 @@ 7. [Message.prototype.setRetryThreshold()](#messageprototypesetretrythreshold) 8. [Message.prototype.getRetryThreshold()](#messageprototypegetretrythreshold) 5. Scheduling parameters - 1. [Message.prototype.setScheduledRepeat()](#messageprototypesetscheduledrepeat) - 2. [Message.prototype.setScheduledPeriod()](#messageprototypesetscheduledperiod) - 3. [Message.prototype.getScheduledPeriod()](#messageprototypegetscheduledperiod) - 4. [Message.prototype.getScheduledRepeat()](#messageprototypegetscheduledrepeat) + 1. [Message.prototype.setScheduledRepeat()](#messageprototypesetscheduledrepeat) + 2. [Message.prototype.getScheduledRepeat()](#messageprototypegetscheduledrepeat) + 3. [Message.prototype.setScheduledRepeatPeriod()](#messageprototypesetscheduledrepeatperiod) + 4. [Message.prototype.getScheduledRepeatPeriod()](#messageprototypegetscheduledrepeatperiod) 5. [Message.prototype.setScheduledCRON()](#messageprototypesetscheduledcron) 6. [Message.prototype.getScheduledCRON()](#messageprototypegetscheduledcron) 7. [Message.prototype.setScheduledDelay()](#messageprototypesetscheduleddelay) @@ -203,7 +203,7 @@ const { Message } = require('redis-smq'); const message = new Message(); message.setScheduledCRON('0 0 * * * *'); // Schedule message for delivery every hour message.setScheduledRepeat(5); -message.setScheduledPeriod(10000); // in millis +message.setScheduledRepeatPeriod(10000); // in millis ``` ### Message.prototype.setScheduledRepeat() @@ -217,18 +217,18 @@ const message = new Message(); message.setScheduledRepeat(6); // integer ``` -### Message.prototype.setScheduledPeriod() +### Message.prototype.setScheduledRepeatPeriod() -Set the amount of time, in milliseconds, to wait for before enqueuing a given message. +Set the amount of time, in milliseconds, to wait for before the next scheduled repeat. -`Message scheduled period` only takes effect when combined with [message scheduled repeat](#messageprototypesetscheduledrepeat). +`repeat period` only takes effect when combined with [message scheduled repeat](#messageprototypesetscheduledrepeat). ```javascript const { Message } = require('redis-smq'); const message = new Message(); message.setScheduledRepeat(6); // Schedule the message for delivery 6 times -message.setScheduledPeriod(1000); // Wait for one second after each delivery +message.setScheduledRepeatPeriod(1000); // Wait for one second after each delivery ``` ### Message.prototype.isPeriodic() @@ -386,15 +386,15 @@ message.setScheduledRepeat(6); message.getScheduledRepeat(); // 6 ```` -### Message.prototype.getScheduledPeriod() +### Message.prototype.getScheduledRepeatPeriod() ```javascript const { Message } = require('redis-smq'); const message = new Message(); message.setScheduledRepeat(6); // Schedule the message for delivery 6 times -message.setScheduledPeriod(1000); // Wait for one second after each delivery -message.getScheduledPeriod(); // 1000, in millis +message.setScheduledRepeatPeriod(1000); // Wait for one second after each delivery +message.getScheduledRepeatPeriod(); // 1000, in millis ``` ### Message.prototype.getScheduledCRON() diff --git a/docs/http-api.md b/docs/http-api.md index e030e685..02e735d2 100644 --- a/docs/http-api.md +++ b/docs/http-api.md @@ -109,7 +109,7 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( "priority": null, "scheduledCron": null, "scheduledDelay": null, - "scheduledPeriod": null, + "scheduledRepeatPeriod": null, "scheduledRepeat": 0, "scheduledCronFired": false, "attempts": 0, @@ -211,7 +211,7 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( "priority": null, "scheduledCron": null, "scheduledDelay": null, - "scheduledPeriod": null, + "scheduledRepeatPeriod": null, "scheduledRepeat": 0, "scheduledCronFired": false, "attempts": 2, @@ -314,7 +314,7 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( "priority": null, "scheduledCron": null, "scheduledDelay": null, - "scheduledPeriod": null, + "scheduledRepeatPeriod": null, "scheduledRepeat": 0, "scheduledCronFired": false, "attempts": 0, @@ -395,7 +395,7 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( "priority": 4, "scheduledCron": null, "scheduledDelay": null, - "scheduledPeriod": null, + "scheduledRepeatPeriod": null, "scheduledRepeat": 0, "scheduledCronFired": false, "attempts": 0, @@ -466,7 +466,7 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( "priority": null, "scheduledCron": null, "scheduledDelay": null, - "scheduledPeriod": 10000, + "scheduledRepeatPeriod": 10000, "scheduledRepeat": 6, "scheduledCronFired": false, "attempts": 0, diff --git a/docs/logs.md b/docs/logs.md index 78e7d3c2..9acdee45 100644 --- a/docs/logs.md +++ b/docs/logs.md @@ -93,7 +93,7 @@ setLogger(logger); [2022-01-27T14:04:29.437Z] INFO: redis-smq/165159 on leno: [Consumer/eec6061a-b60f-4bb7-a5f9-066d4b5022cf] Up and running... [2022-01-27T14:04:30.538Z] INFO: redis-smq/165159 on leno: [Consumer/eec6061a-b60f-4bb7-a5f9-066d4b5022cf] Created a new instance (ID: 4f8bae2f-27a1-4953-9131-ba1fe216ade0) for MessageHandler ({"queue":{"name":"test_queue","ns":"testing"},"usePriorityQueuing":false}). [2022-01-27T14:04:30.546Z] INFO: redis-smq/165159 on leno: [MessageHandler/4f8bae2f-27a1-4953-9131-ba1fe216ade0] Up and running... -[2022-01-27T14:04:30.549Z] INFO: redis-smq/165159 on leno: [MessageHandler/4f8bae2f-27a1-4953-9131-ba1fe216ade0] Consuming message (ID 63326dab-20a2-46f7-b196-8163380d9b71) with properties ({"queue":{"name":"test_queue","ns":"testing"},"ttl":0,"retryThreshold":3,"retryDelay":0,"consumeTimeout":0,"body":{"hello":"world"},"priority":null,"scheduledCron":null,"scheduledDelay":null,"scheduledPeriod":null,"scheduledRepeat":0,"publishedAt":1643292269426,"scheduledAt":null,"scheduledCronFired":false,"attempts":0,"scheduledRepeatCount":0,"delayed":false,"expired":false,"createdAt":1643292269362,"uuid":"63326dab-20a2-46f7-b196-8163380d9b71"}) +[2022-01-27T14:04:30.549Z] INFO: redis-smq/165159 on leno: [MessageHandler/4f8bae2f-27a1-4953-9131-ba1fe216ade0] Consuming message (ID 63326dab-20a2-46f7-b196-8163380d9b71) with properties ({"queue":{"name":"test_queue","ns":"testing"},"ttl":0,"retryThreshold":3,"retryDelay":0,"consumeTimeout":0,"body":{"hello":"world"},"priority":null,"scheduledCron":null,"scheduledDelay":null,"scheduledRepeatPeriod":null,"scheduledRepeat":0,"publishedAt":1643292269426,"scheduledAt":null,"scheduledCronFired":false,"attempts":0,"scheduledRepeatCount":0,"delayed":false,"expired":false,"createdAt":1643292269362,"uuid":"63326dab-20a2-46f7-b196-8163380d9b71"}) [2022-01-27T14:04:30.551Z] INFO: redis-smq/165159 on leno: [MessageHandler/4f8bae2f-27a1-4953-9131-ba1fe216ade0] Message (ID 63326dab-20a2-46f7-b196-8163380d9b71) acknowledged [2022-01-27T14:04:30.580Z] INFO: redis-smq/165159 on leno: [MessageManager] Acknowledged message (ID 63326dab-20a2-46f7-b196-8163380d9b71) has been deleted [2022-01-27T14:04:30.590Z] INFO: redis-smq/165159 on leno: [Consumer/eec6061a-b60f-4bb7-a5f9-066d4b5022cf] Going down... diff --git a/docs/scheduling-messages.md b/docs/scheduling-messages.md index 77be1ed6..7274e572 100644 --- a/docs/scheduling-messages.md +++ b/docs/scheduling-messages.md @@ -4,10 +4,10 @@ Starting with version 1.0.19, RedisSMQ enables you to schedule a one-time or rep To set up scheduling parameters for a given message, the [Message API](api/message.md) provides: -- [setScheduledPeriod()](api/message.md#messageprototypesetscheduledperiod) - [setScheduledDelay()](api/message.md#messageprototypesetscheduleddelay) - [setScheduledCRON()](api/message.md#messageprototypesetscheduledcron) - [setScheduledRepeat()](api/message.md#messageprototypesetscheduledrepeat) +- [setScheduledRepeatPeriod()](api/message.md#messageprototypesetscheduledrepeatperiod) To schedule your message, you can publish it, as any other message, from your [Producer](api/producer.md#producerprototypeproduce) using the `produce()` method. diff --git a/src/monitor-server/controllers/common/dto/queues/message.DTO.ts b/src/monitor-server/controllers/common/dto/queues/message.DTO.ts index 0ffcea99..64974e12 100644 --- a/src/monitor-server/controllers/common/dto/queues/message.DTO.ts +++ b/src/monitor-server/controllers/common/dto/queues/message.DTO.ts @@ -84,7 +84,7 @@ export class MessageDTO { @IsInt() @IsOptional() - scheduledPeriod: number | null = null; + scheduledRepeatPeriod: number | null = null; @IsInt() scheduledRepeat!: number; diff --git a/src/system/app/message/message.ts b/src/system/app/message/message.ts index 92bb5133..28c6937d 100644 --- a/src/system/app/message/message.ts +++ b/src/system/app/message/message.ts @@ -39,7 +39,7 @@ export class Message { protected scheduledDelay: number | null = null; - protected scheduledPeriod: number | null = null; + protected scheduledRepeatPeriod: number | null = null; protected scheduledRepeat = 0; @@ -121,7 +121,7 @@ export class Message { /** * @param period In millis */ - setScheduledPeriod(period: number): Message { + setScheduledRepeatPeriod(period: number): Message { // JavaScript users do not have type checking // So just make sure that we have an integer value const value = Number(period); @@ -130,7 +130,7 @@ export class Message { 'Expected a positive integer value in milliseconds', ); } - this.scheduledPeriod = value; + this.scheduledRepeatPeriod = value; return this; } @@ -295,8 +295,8 @@ export class Message { return this.scheduledRepeat; } - getScheduledPeriod(): number | null { - return this.scheduledPeriod; + getScheduledRepeatPeriod(): number | null { + return this.scheduledRepeatPeriod; } getScheduledCRON(): string | null { @@ -336,10 +336,10 @@ export class Message { if (msgScheduledRepeat) { const newCount = metadata.getMessageScheduledRepeatCount() + 1; if (newCount <= msgScheduledRepeat) { - const msgScheduledPeriod = this.getScheduledPeriod(); + const scheduledRepeatPeriod = this.getScheduledRepeatPeriod(); const now = Date.now(); - if (msgScheduledPeriod) { - repeatTimestamp = now + msgScheduledPeriod; + if (scheduledRepeatPeriod) { + repeatTimestamp = now + scheduledRepeatPeriod; } else { repeatTimestamp = now; } diff --git a/tests/scheduling-messages/test00004.test.ts b/tests/scheduling-messages/test00004.test.ts index 6991107a..22b707f2 100644 --- a/tests/scheduling-messages/test00004.test.ts +++ b/tests/scheduling-messages/test00004.test.ts @@ -12,7 +12,7 @@ test('Schedule a message: combine CRON, REPEAT, REPEAT PERIOD', async () => { const msg = new Message(); msg.setScheduledCRON('*/20 * * * * *'); // Schedule message for each 30 seconds msg.setScheduledRepeat(2); // repeat 2 times - msg.setScheduledPeriod(5000); // 5 secs between each repeat + msg.setScheduledRepeatPeriod(5000); // 5 secs between each repeat msg.setQueue(defaultQueue); const producer = getProducer(); await producer.produceAsync(msg); diff --git a/tests/scheduling-messages/test00005.test.ts b/tests/scheduling-messages/test00005.test.ts index 82d31901..b098ddb8 100644 --- a/tests/scheduling-messages/test00005.test.ts +++ b/tests/scheduling-messages/test00005.test.ts @@ -12,7 +12,7 @@ test('Schedule a message: combine CRON, REPEAT, REPEAT PERIOD, DELAY', async () const msg = new Message(); msg.setScheduledCRON('*/20 * * * * *'); // Schedule message for each 20 seconds msg.setScheduledRepeat(2); // repeat 2 times - msg.setScheduledPeriod(5000); // 5 secs between each repeat + msg.setScheduledRepeatPeriod(5000); // 5 secs between each repeat msg.setScheduledDelay(15000); // this will first delay the message for 15 secs before cron/repeat scheduling msg.setBody({ hello: 'world' }).setQueue(defaultQueue); diff --git a/tests/scheduling-messages/test00006.test.ts b/tests/scheduling-messages/test00006.test.ts index 56dc6d6a..b2eac17c 100644 --- a/tests/scheduling-messages/test00006.test.ts +++ b/tests/scheduling-messages/test00006.test.ts @@ -13,7 +13,7 @@ test('Schedule a message: combine REPEAT, REPEAT PERIOD, DELAY. Case 1', async ( msg .setScheduledDelay(10000) .setScheduledRepeat(3) - .setScheduledPeriod(3000) + .setScheduledRepeatPeriod(3000) .setBody({ hello: 'world' }) .setQueue(defaultQueue); diff --git a/tests/scheduling-messages/test00007.test.ts b/tests/scheduling-messages/test00007.test.ts index 23837186..58e40609 100644 --- a/tests/scheduling-messages/test00007.test.ts +++ b/tests/scheduling-messages/test00007.test.ts @@ -13,7 +13,7 @@ test('Schedule a message: combine REPEAT, REPEAT PERIOD, DELAY. Case 2', async ( msg .setScheduledDelay(10000) .setScheduledRepeat(0) // should not be repeated - .setScheduledPeriod(3000) + .setScheduledRepeatPeriod(3000) .setBody({ hello: 'world' }) .setQueue(defaultQueue);