Skip to content

Commit 6aa0b46

Browse files
committed
refactor: change timestamp attribute names for Clarity
1 parent 41f0f68 commit 6aa0b46

17 files changed

+199
-199
lines changed

README.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ The `dynamomq` command-line interface provides a range of commands to interact w
143143

144144
- `--endpoint-url`: Override the default URL for commands with a specified endpoint URL.
145145
- `-h`, `--help`: Display help information for `dynamomq`.
146-
- `--queueing-index-name`: Specify the name of the queueing index to use (default is `"dynamo-mq-index-queue_type-queue_add_timestamp"`).
146+
- `--queueing-index-name`: Specify the name of the queueing index to use (default is `"dynamo-mq-index-queue_type-sent_at"`).
147147
- `--table-name`: Define the name of the DynamoDB table to contain the items (default is `"dynamo-mq-table"`).
148148

149149
To get more detailed information about a specific command, use `dynamomq [command] --help`.
@@ -333,33 +333,33 @@ This design ensures that DynamoMQ maintains message reliability while enabling t
333333

334334
The DynamoDB table for the DynamoMQ message queue system is designed to efficiently manage and track the status of messages. Here’s a breakdown of the table schema:
335335

336-
| Key | Attributes | Type | Example Value |
337-
|-------|------------------------|--------|-------------------------------------|
338-
| PK | id | string | A-101 |
339-
| | data | any | any |
340-
| | visibility_timeout | number | 10 |
341-
| | receive_count | number | 1 |
342-
| GSIPK | queue_type | string | STANDARD or DLQ |
343-
| | version | number | 1 |
344-
| | creation_timestamp | string | 2006-01-02T15:04:05.999999999Z07:00 |
345-
| | last_updated_timestamp | string | 2006-01-02T15:04:05.999999999Z07:00 |
346-
| GSISK | queue_add_timestamp | string | 2006-01-02T15:04:05.999999999Z07:00 |
347-
| | queue_peek_timestamp | string | 2006-01-02T15:04:05.999999999Z07:00 |
336+
| Key | Attributes | Type | Example Value |
337+
|-------|--------------------|--------|-------------------------------------|
338+
| PK | id | string | A-101 |
339+
| | data | any | any |
340+
| | visibility_timeout | number | 10 |
341+
| | receive_count | number | 1 |
342+
| GSIPK | queue_type | string | STANDARD or DLQ |
343+
| | version | number | 1 |
344+
| | created_at | string | 2006-01-02T15:04:05.999999999Z07:00 |
345+
| | updated_at | string | 2006-01-02T15:04:05.999999999Z07:00 |
346+
| GSISK | sent_at | string | 2006-01-02T15:04:05.999999999Z07:00 |
347+
| | received_at | string | 2006-01-02T15:04:05.999999999Z07:00 |
348348

349349
**PK (Primary Key)** `ID`: A unique identifier for each message, such as 'A-101'. This is a string value that facilitates the retrieval and management of messages.
350350

351351
**GSIPK (Global Secondary Index - Partition Key)** `queue_type`: Used to categorize messages by `queue_type`, such as 'STANDARD' or 'DLQ' (Dead Letter Queue), allowing for quick access and operations on subsets of the queue.
352352

353-
**GSISK (Global Secondary Index - Sort Key)** `queue_add_timestamp`: The timestamp when the message was added to the queue. Facilitates the ordering of messages based on the time they were added to the queue, which is useful for implementing FIFO (First-In-First-Out) or other ordering mechanisms.
353+
**GSISK (Global Secondary Index - Sort Key)** `sent_at`: The timestamp when the message was sent to the queue. Facilitates the ordering of messages based on the time they were added to the queue, which is useful for implementing FIFO (First-In-First-Out) or other ordering mechanisms.
354354

355355
**Attributes**: These are the various properties associated with each message:
356356
- `data`: This attribute holds the content of the message and can be of any type.
357357
- `isibility_timeout`: The new value for the message's visibility timeout (in seconds).
358358
- `receive_count`: A numerical count of how many times the message has been retrieved from the queue.
359359
- `version`: A number that can be used for optimistic locking and to ensure that the message is not being concurrently modified.
360-
- `creation_timestamp`: The date and time when the message was created. ISO 8601 format.
361-
- `last_updated_timestamp`: The date and time when the message was last updated. ISO 8601 format.
362-
- `queue_peek_timestamp`: The timestamp when the message was last viewed without being altered. ISO 8601 format.
360+
- `created_at`: The date and time when the message was created. ISO 8601 format.
361+
- `updated_at`: The date and time when the message was last updated. ISO 8601 format.
362+
- `received_at`: The timestamp when the message was last viewed without being altered. ISO 8601 format.
363363

364364
### Data Transition
365365

client.go

+54-54
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
const (
1818
DefaultTableName = "dynamo-mq-table"
19-
DefaultQueueingIndexName = "dynamo-mq-index-queue_type-queue_add_timestamp"
19+
DefaultQueueingIndexName = "dynamo-mq-index-queue_type-sent_at"
2020
DefaultRetryMaxAttempts = 10
2121
DefaultVisibilityTimeoutInSeconds = 30
2222
DefaultMaxListMessages = 10
@@ -170,18 +170,18 @@ func (c *client[T]) SendMessage(ctx context.Context, params *SendMessageInput[T]
170170
now := c.clock.Now()
171171
message := NewMessage(params.ID, params.Data, now)
172172
if params.DelaySeconds > 0 {
173-
message.delayToAddQueueTimestamp(time.Duration(params.DelaySeconds) * time.Second)
173+
message.delayToSentAt(time.Duration(params.DelaySeconds) * time.Second)
174174
}
175175
err = c.put(ctx, message)
176176
if err != nil {
177177
return &SendMessageOutput[T]{}, err
178178
}
179179
return &SendMessageOutput[T]{
180180
Result: &Result{
181-
ID: message.ID,
182-
Status: message.GetStatus(now),
183-
LastUpdatedTimestamp: message.LastUpdatedTimestamp,
184-
Version: message.Version,
181+
ID: message.ID,
182+
Status: message.GetStatus(now),
183+
UpdatedAt: message.UpdatedAt,
184+
Version: message.Version,
185185
},
186186
Message: message,
187187
}, nil
@@ -194,9 +194,9 @@ type ReceiveMessageInput struct {
194194

195195
// ReceiveMessageOutput represents the result for the ReceiveMessage() API call.
196196
type ReceiveMessageOutput[T any] struct {
197-
*Result // Embedded type for inheritance-like behavior in Go
198-
PeekFromQueueTimestamp string `json:"queue_peek_timestamp"`
199-
PeekedMessageObject *Message[T] `json:"-"`
197+
*Result // Embedded type for inheritance-like behavior in Go
198+
ReceivedAt string `json:"received_at"`
199+
ReceivedMessage *Message[T] `json:"-"`
200200
}
201201

202202
func (c *client[T]) ReceiveMessage(ctx context.Context, params *ReceiveMessageInput) (*ReceiveMessageOutput[T], error) {
@@ -219,13 +219,13 @@ func (c *client[T]) ReceiveMessage(ctx context.Context, params *ReceiveMessageIn
219219

220220
return &ReceiveMessageOutput[T]{
221221
Result: &Result{
222-
ID: updated.ID,
223-
Status: updated.GetStatus(c.clock.Now()),
224-
LastUpdatedTimestamp: updated.LastUpdatedTimestamp,
225-
Version: updated.Version,
222+
ID: updated.ID,
223+
Status: updated.GetStatus(c.clock.Now()),
224+
UpdatedAt: updated.UpdatedAt,
225+
Version: updated.Version,
226226
},
227-
PeekFromQueueTimestamp: updated.PeekFromQueueTimestamp,
228-
PeekedMessageObject: updated,
227+
ReceivedAt: updated.ReceivedAt,
228+
ReceivedMessage: updated,
229229
}, nil
230230
}
231231

@@ -304,8 +304,8 @@ func (c *client[T]) processSelectedMessage(ctx context.Context, message *Message
304304
Add(expression.Name("version"), expression.Value(1)).
305305
Add(expression.Name("receive_count"), expression.Value(1)).
306306
Set(expression.Name("visibility_timeout"), expression.Value(message.VisibilityTimeout)).
307-
Set(expression.Name("last_updated_timestamp"), expression.Value(message.LastUpdatedTimestamp)).
308-
Set(expression.Name("queue_peek_timestamp"), expression.Value(message.PeekFromQueueTimestamp))).
307+
Set(expression.Name("updated_at"), expression.Value(message.UpdatedAt)).
308+
Set(expression.Name("received_at"), expression.Value(message.ReceivedAt))).
309309
WithCondition(expression.Name("version").Equal(expression.Value(message.Version)))
310310
expr, err := c.buildExpression(builder)
311311
if err != nil {
@@ -347,7 +347,7 @@ func (c *client[T]) ChangeMessageVisibility(ctx context.Context, params *ChangeM
347347
builder := expression.NewBuilder().
348348
WithUpdate(expression.
349349
Add(expression.Name("version"), expression.Value(1)).
350-
Set(expression.Name("last_updated_timestamp"), expression.Value(message.LastUpdatedTimestamp)).
350+
Set(expression.Name("updated_at"), expression.Value(message.UpdatedAt)).
351351
Set(expression.Name("visibility_timeout"), expression.Value(message.VisibilityTimeout))).
352352
WithCondition(expression.Name("version").Equal(expression.Value(message.Version)))
353353
expr, err := c.buildExpression(builder)
@@ -360,10 +360,10 @@ func (c *client[T]) ChangeMessageVisibility(ctx context.Context, params *ChangeM
360360
}
361361
return &ChangeMessageVisibilityOutput[T]{
362362
Result: &Result{
363-
ID: retried.ID,
364-
Status: retried.GetStatus(c.clock.Now()),
365-
LastUpdatedTimestamp: retried.LastUpdatedTimestamp,
366-
Version: retried.Version,
363+
ID: retried.ID,
364+
Status: retried.GetStatus(c.clock.Now()),
365+
UpdatedAt: retried.UpdatedAt,
366+
Version: retried.Version,
367367
},
368368
Message: retried,
369369
}, nil
@@ -402,10 +402,10 @@ type MoveMessageToDLQInput struct {
402402
}
403403

404404
type MoveMessageToDLQOutput struct {
405-
ID string `json:"id"`
406-
Status Status `json:"status"`
407-
LastUpdatedTimestamp string `json:"last_updated_timestamp"`
408-
Version int `json:"version"`
405+
ID string `json:"id"`
406+
Status Status `json:"status"`
407+
UpdatedAt string `json:"updated_at"`
408+
Version int `json:"version"`
409409
}
410410

411411
func (c *client[T]) MoveMessageToDLQ(ctx context.Context, params *MoveMessageToDLQInput) (*MoveMessageToDLQOutput, error) {
@@ -425,10 +425,10 @@ func (c *client[T]) MoveMessageToDLQ(ctx context.Context, params *MoveMessageToD
425425
if markedErr := message.markAsMovedToDLQ(c.clock.Now()); markedErr != nil {
426426
//lint:ignore nilerr reason
427427
return &MoveMessageToDLQOutput{
428-
ID: params.ID,
429-
Status: message.GetStatus(c.clock.Now()),
430-
LastUpdatedTimestamp: message.LastUpdatedTimestamp,
431-
Version: message.Version,
428+
ID: params.ID,
429+
Status: message.GetStatus(c.clock.Now()),
430+
UpdatedAt: message.UpdatedAt,
431+
Version: message.Version,
432432
}, nil
433433
}
434434
builder := expression.NewBuilder().
@@ -437,9 +437,9 @@ func (c *client[T]) MoveMessageToDLQ(ctx context.Context, params *MoveMessageToD
437437
Set(expression.Name("visibility_timeout"), expression.Value(message.VisibilityTimeout)).
438438
Set(expression.Name("receive_count"), expression.Value(message.ReceiveCount)).
439439
Set(expression.Name("queue_type"), expression.Value(message.QueueType)).
440-
Set(expression.Name("last_updated_timestamp"), expression.Value(message.LastUpdatedTimestamp)).
441-
Set(expression.Name("queue_add_timestamp"), expression.Value(message.AddToQueueTimestamp)).
442-
Set(expression.Name("queue_peek_timestamp"), expression.Value(message.AddToQueueTimestamp))).
440+
Set(expression.Name("updated_at"), expression.Value(message.UpdatedAt)).
441+
Set(expression.Name("sent_at"), expression.Value(message.SentAt)).
442+
Set(expression.Name("received_at"), expression.Value(message.SentAt))).
443443
WithCondition(expression.Name("version").Equal(expression.Value(message.Version)))
444444
expr, err := c.buildExpression(builder)
445445
if err != nil {
@@ -450,10 +450,10 @@ func (c *client[T]) MoveMessageToDLQ(ctx context.Context, params *MoveMessageToD
450450
return &MoveMessageToDLQOutput{}, err
451451
}
452452
return &MoveMessageToDLQOutput{
453-
ID: params.ID,
454-
Status: updated.GetStatus(c.clock.Now()),
455-
LastUpdatedTimestamp: updated.LastUpdatedTimestamp,
456-
Version: updated.Version,
453+
ID: params.ID,
454+
Status: updated.GetStatus(c.clock.Now()),
455+
UpdatedAt: updated.UpdatedAt,
456+
Version: updated.Version,
457457
}, nil
458458
}
459459

@@ -462,10 +462,10 @@ type RedriveMessageInput struct {
462462
}
463463

464464
type RedriveMessageOutput struct {
465-
ID string `json:"id"`
466-
Status Status `json:"status"`
467-
LastUpdatedTimestamp string `json:"last_updated_timestamp"`
468-
Version int `json:"version"`
465+
ID string `json:"id"`
466+
Status Status `json:"status"`
467+
UpdatedAt string `json:"updated_at"`
468+
Version int `json:"version"`
469469
}
470470

471471
func (c *client[T]) RedriveMessage(ctx context.Context, params *RedriveMessageInput) (*RedriveMessageOutput, error) {
@@ -497,11 +497,11 @@ func (c *client[T]) RedriveMessage(ctx context.Context, params *RedriveMessageIn
497497
expression.Name("visibility_timeout"),
498498
expression.Value(message.VisibilityTimeout),
499499
).Set(
500-
expression.Name("last_updated_timestamp"),
501-
expression.Value(message.LastUpdatedTimestamp),
500+
expression.Name("updated_at"),
501+
expression.Value(message.UpdatedAt),
502502
).Set(
503-
expression.Name("queue_add_timestamp"),
504-
expression.Value(message.AddToQueueTimestamp),
503+
expression.Name("sent_at"),
504+
expression.Value(message.SentAt),
505505
)).
506506
WithCondition(expression.Name("version").
507507
Equal(expression.Value(message.Version)))
@@ -514,10 +514,10 @@ func (c *client[T]) RedriveMessage(ctx context.Context, params *RedriveMessageIn
514514
return &RedriveMessageOutput{}, err
515515
}
516516
return &RedriveMessageOutput{
517-
ID: updated.ID,
518-
Status: updated.GetStatus(c.clock.Now()),
519-
LastUpdatedTimestamp: updated.LastUpdatedTimestamp,
520-
Version: updated.Version,
517+
ID: updated.ID,
518+
Status: updated.GetStatus(c.clock.Now()),
519+
UpdatedAt: updated.UpdatedAt,
520+
Version: updated.Version,
521521
}, nil
522522
}
523523

@@ -758,7 +758,7 @@ func (c *client[T]) ListMessages(ctx context.Context, params *ListMessagesInput)
758758
return &ListMessagesOutput[T]{}, UnmarshalingAttributeError{Cause: err}
759759
}
760760
sort.Slice(messages, func(i, j int) bool {
761-
return messages[i].LastUpdatedTimestamp < messages[j].LastUpdatedTimestamp
761+
return messages[i].UpdatedAt < messages[j].UpdatedAt
762762
})
763763
return &ListMessagesOutput[T]{Messages: messages}, nil
764764
}
@@ -860,8 +860,8 @@ const (
860860
)
861861

862862
type Result struct {
863-
ID string `json:"id"`
864-
Status Status `json:"status"`
865-
LastUpdatedTimestamp string `json:"last_updated_timestamp"`
866-
Version int `json:"version"`
863+
ID string `json:"id"`
864+
Status Status `json:"status"`
865+
UpdatedAt string `json:"updated_at"`
866+
Version int `json:"version"`
867867
}

0 commit comments

Comments
 (0)