Skip to content

Commit

Permalink
Merge pull request #15 from maugustoo/fix-ttl-timestamp
Browse files Browse the repository at this point in the history
change ttl time from milliseconds to seconds
  • Loading branch information
rpinheiroalmeida authored Oct 15, 2021
2 parents 7779d5e + 4f62dc1 commit bf42d15
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ The object DynamodbConfig is related to Dynamodb configuration, the possible par
| endpointUrl | An Endpoint object representing the endpoint URL for service requests. |
| maxRetries | The maximum amount of retries to attempt with a request. |
| httpOptions | A set of options to pass to the low-level HTTP request. |
| ttl | Time to Live (TTL) on the specified table. |
| ttl | Time to Live (TTL) in seconds on the specified table. |


### Adding Events
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aws-event-stream",
"version": "1.2.4",
"version": "1.2.5",
"description": "A simple and fast EventStore for AWS.",
"author": "Rodrigo Pinheiro de Almeida <[email protected]>",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion src/provider/dynamodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ export class DynamodbProvider implements PersistenceProvider {
await this.ensureTables();
const now = new Date();
const commitTimestamp = now.getTime();
const commitTimetampSeconds = Math.floor(commitTimestamp / 1000);
const event = {
aggregation_streamid: `${this.getKey(stream)}`,
commitTimestamp: commitTimestamp,
eventType: data.eventType,
payload: data,
stream: stream,
ttl: this.config.dynamodb.ttl ? (commitTimestamp + this.config.dynamodb.ttl) : undefined,
ttl: this.config.dynamodb.ttl ? (commitTimetampSeconds + this.config.dynamodb.ttl) : undefined,
};
const record = {
Item: event,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/provider/dynamodb-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('EventStory Dynamodb Provider', () => {
aggregation_streamid: 'orders:1',
commitTimestamp: NOW.getTime(),
eventType: 'SENT',
ttl: NOW.getTime() + 10,
ttl: Math.floor(NOW.getTime() / 1000) + 10,
payload: {
eventType: 'SENT',
text: 'EVENT PAYLOAD'
Expand Down

0 comments on commit bf42d15

Please sign in to comment.