|
1 | 1 | import { join } from 'path';
|
2 | 2 | import { inject, singleton } from 'tsyringe';
|
3 | 3 | import { Logger } from '@map-colonies/js-logger';
|
4 |
| -import { DATA_DIR, DEFAULT_SEQUENCE_NUMBER, SEQUENCE_NUMBER_REGEX, SERVICES, STATE_FILE } from '../../../common/constants'; |
| 4 | +import { DATA_DIR, DEFAULT_SEQUENCE_NUMBER, SEQUENCE_NUMBER_REGEX, SERVICES, STATE_FILE, TIMESTAMP_REGEX } from '../../../common/constants'; |
5 | 5 | import { BucketDoesNotExistError, InvalidStateFileError } from '../../../common/errors';
|
6 | 6 | import { createDirectory, fetchSequenceNumber, streamToString } from '../../../common/util';
|
7 | 7 | import { ReplicationClient } from '../../../httpClient/replicationClient';
|
@@ -95,6 +95,29 @@ export class StateTracker {
|
95 | 95 | this.totalAppends++;
|
96 | 96 | }
|
97 | 97 |
|
| 98 | + public async updateRemoteTimestamp(): Promise<void> { |
| 99 | + const updatedTimestamp = new Date() |
| 100 | + .toISOString() |
| 101 | + .replace(/\.\d+Z$/, 'Z') |
| 102 | + .replace(/:/g, '\\:'); |
| 103 | + |
| 104 | + this.logger.info({ |
| 105 | + msg: 'attempting to update remote timestamp on configured bucket', |
| 106 | + projectId: this.projectId, |
| 107 | + currentState: this.current, |
| 108 | + toState: this.nextState, |
| 109 | + bucketName: this.s3Client.bucketName, |
| 110 | + acl: this.s3Client.acl, |
| 111 | + updatedTimestamp, |
| 112 | + }); |
| 113 | + |
| 114 | + stateContent = stateContent.replace(TIMESTAMP_REGEX, `timestamp=${updatedTimestamp}`); |
| 115 | + const stateBuffer = Buffer.from(stateContent, 'utf-8'); |
| 116 | + const stateKey = join(this.projectId, STATE_FILE); |
| 117 | + |
| 118 | + await this.s3Client.putObjectWrapper(stateKey, stateBuffer); |
| 119 | + } |
| 120 | + |
98 | 121 | private fetchSequenceNumberSafely(content: string): number {
|
99 | 122 | try {
|
100 | 123 | return fetchSequenceNumber(content);
|
|
0 commit comments