Skip to content

Commit

Permalink
Rename setScheduledPeriod() to setScheduledRepeatPeriod()
Browse files Browse the repository at this point in the history
  • Loading branch information
weyoss committed Feb 4, 2022
1 parent d9c50f3 commit d6e3376
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 32 deletions.
24 changes: 12 additions & 12 deletions docs/api/message.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions docs/http-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion docs/logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
2 changes: 1 addition & 1 deletion docs/scheduling-messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class MessageDTO {

@IsInt()
@IsOptional()
scheduledPeriod: number | null = null;
scheduledRepeatPeriod: number | null = null;

@IsInt()
scheduledRepeat!: number;
Expand Down
16 changes: 8 additions & 8 deletions src/system/app/message/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -130,7 +130,7 @@ export class Message {
'Expected a positive integer value in milliseconds',
);
}
this.scheduledPeriod = value;
this.scheduledRepeatPeriod = value;
return this;
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/scheduling-messages/test00004.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/scheduling-messages/test00005.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/scheduling-messages/test00006.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/scheduling-messages/test00007.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit d6e3376

Please sign in to comment.