Skip to content

Commit a77db26

Browse files
committed
crm: set timeout when doing cohort queries
1 parent 5b936af commit a77db26

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/packages/frontend/client/query.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ export class QueryClient {
2323
// opts.cb is NOT specified. When opts.cb is specified,
2424
// it works like a cb and returns nothing. For changefeeds
2525
// you MUST specify opts.cb, but can always optionally do so.
26-
public async query(opts: {
26+
query = async (opts: {
2727
query: object;
2828
options?: object[]; // if given must be an array of objects, e.g., [{limit:5}]
2929
changes?: boolean;
30+
timeout?: number; // ms
3031
cb?: CB; // support old cb interface
31-
}): Promise<any> {
32+
}): Promise<any> => {
3233
// Deprecation warnings:
33-
for (const field of ["standby", "timeout", "no_post", "ignore_response"]) {
34+
for (const field of ["standby", "no_post", "ignore_response"]) {
3435
if (opts[field] != null) {
3536
console.trace(`WARNING: passing '${field}' to query is deprecated`);
3637
}
@@ -75,6 +76,7 @@ export class QueryClient {
7576
const query = await this.client.conat_client.hub.db.userQuery({
7677
query: opts.query,
7778
options: opts.options,
79+
timeout: opts.timeout,
7880
});
7981

8082
if (opts.cb == null) {
@@ -90,12 +92,12 @@ export class QueryClient {
9092
}
9193
}
9294
}
93-
}
95+
};
9496

9597
// cancel a changefeed created above. This is ONLY used
9698
// right now by the CRM code.
97-
public async cancel(id: string): Promise<void> {
99+
cancel = async (id: string): Promise<void> => {
98100
this.changefeeds[id]?.close();
99101
delete this.changefeeds[id];
100-
}
102+
};
101103
}

src/packages/frontend/conat/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ export class ConatClient extends EventEmitter {
303303
args: any[];
304304
timeout?: number;
305305
}) => {
306+
console.log("callHub", { name, args, timeout });
306307
const cn = this.conat();
307308
const subject = `hub.account.${this.client.account_id}.${service}`;
308309
try {

src/packages/frontend/frame-editors/crm-editor/views/retention/update.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default async function update(
3333
{ model, start, stop, period, dataEnd = new Date() }: Retention,
3434
setCancelRef,
3535
onProgress: (string, percentDone) => void,
36-
cacheOnly?: boolean
36+
cacheOnly?: boolean,
3737
): Promise<Data[] | null> {
3838
start = startOfDayUTC(start);
3939
stop = startOfDayUTC(dayjs(stop).add(1, "day"));
@@ -70,11 +70,12 @@ export default async function update(
7070
`${
7171
last ? "Got " + last + ". " : ""
7272
}Processing cohort interval ${interval}...`,
73-
progress
73+
progress,
7474
);
7575

7676
// Query the database for the current cohort interval
7777
const result = await webapp_client.async_query({
78+
timeout: 2 * 60000, // it can take a while when there is a lot of data.
7879
query: {
7980
crm_retention: {
8081
start: intervalStart,
@@ -90,14 +91,14 @@ export default async function update(
9091
last = JSON.stringify(result.query.crm_retention);
9192
if (FAKE_DATA) {
9293
const size = (result.query.crm_retention.size = Math.round(
93-
Math.random() * 1000
94+
Math.random() * 1000,
9495
));
9596
let n = size * Math.random();
9697
result.query.crm_retention.active = result.query.crm_retention.active.map(
9798
(_) => {
9899
n = Math.min(size, Math.round(n * 1.3 * Math.random()));
99100
return n;
100-
}
101+
},
101102
);
102103
}
103104
data.push(result.query.crm_retention);

0 commit comments

Comments
 (0)