Skip to content

Commit 3ca24bc

Browse files
authored
feat(API): Add organisation ID to queue jobs that only contain the statement ID (LLC-592) (#716)
1 parent 1e22547 commit 3ca24bc

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/apps/statements/repo/eventsRepo/emitNewStatements/Signature.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Member from 'jscommons/dist/utils/Member';
22

33
export interface Opts {
4-
readonly ids: string[];
4+
readonly statementProperties: string[];
55
}
66

77
type Signature = Member<Opts, void>;

src/apps/statements/repo/eventsRepo/emitNewStatements/redis.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ const EVENT_NAME = 'statement.new';
55
const CHANNEL_NAME = 'statement.notify';
66

77
export default (config: FacadeConfig): Signature => {
8-
return async ({ ids }) => {
8+
return async ({ statementProperties }) => {
99
const client = await config.client();
1010
const listName = `${config.prefix}:${EVENT_NAME}`;
1111
const channelName = `${config.prefix}:${CHANNEL_NAME}`;
12-
await client.rpush(listName, ...ids);
12+
await client.rpush(listName, ...statementProperties);
1313
client.publish(channelName, '');
1414
};
1515
};

src/apps/statements/service/storeStatements/index.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ export default (config: Config) => {
5454
return postValidatedModel.statement.id;
5555
});
5656

57-
const unstoredStatementIds = unstoredModels.map((unstoredModel) => {
58-
return unstoredModel.statement.id;
59-
});
57+
const unstoredStatementProperties = unstoredModels.map(
58+
(unstoredModel) => JSON.stringify({
59+
statementId: unstoredModel.statement.id,
60+
organisationId: unstoredModel.organisation,
61+
}),
62+
);
6063

6164
// Completes actions that do not need to be awaited.
6265
const unawaitedUpdates: Promise<any> = Promise.all([
@@ -71,11 +74,12 @@ export default (config: Config) => {
7174
});
7275

7376
await awaitUpdates(config, unawaitedUpdates);
74-
if (unstoredStatementIds.length !== 0) {
75-
config.repo.emitNewStatements({ ids: unstoredStatementIds }).catch((err) => {
76-
/* istanbul ignore next */
77-
console.error(err); // tslint:disable-line:no-console
78-
});
77+
if (unstoredStatementProperties.length !== 0) {
78+
config.repo.emitNewStatements({ statementProperties: unstoredStatementProperties })
79+
.catch((err) => {
80+
/* istanbul ignore next */
81+
console.error(err); // tslint:disable-line:no-console
82+
});
7983
}
8084

8185
const tracker = await config.tracker;

0 commit comments

Comments
 (0)