-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathrunQueue.server.ts
More file actions
74 lines (65 loc) · 2.4 KB
/
runQueue.server.ts
File metadata and controls
74 lines (65 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { type AuthenticatedEnvironment } from "~/services/apiAuth.server";
import { marqs } from "./marqs/index.server";
import { engine } from "./runEngine.server";
// Re-export pure utility function from durations.ts (testable without env deps)
export { parseDurationToMs } from "./utils/durations";
//This allows us to update MARQS and the RunQueue
/** Rate limit configuration for a queue */
export type QueueRateLimitConfig = {
/** Maximum number of requests allowed in the period */
limit: number;
/** Time window in milliseconds */
periodMs: number;
/** Optional burst allowance (defaults to limit) */
burst?: number;
};
/** Updates MARQS and the RunQueue limits */
export async function updateEnvConcurrencyLimits(
environment: AuthenticatedEnvironment,
maximumConcurrencyLimit?: number
) {
let updatedEnvironment = environment;
if (maximumConcurrencyLimit !== undefined) {
updatedEnvironment.maximumConcurrencyLimit = maximumConcurrencyLimit;
}
await Promise.allSettled([
marqs?.updateEnvConcurrencyLimits(updatedEnvironment),
engine.runQueue.updateEnvConcurrencyLimits(updatedEnvironment),
]);
}
/** Updates MARQS and the RunQueue limits for a queue */
export async function updateQueueConcurrencyLimits(
environment: AuthenticatedEnvironment,
queueName: string,
concurrency: number
) {
await Promise.allSettled([
marqs?.updateQueueConcurrencyLimits(environment, queueName, concurrency),
engine.runQueue.updateQueueConcurrencyLimits(environment, queueName, concurrency),
]);
}
/** Removes MARQS and the RunQueue limits for a queue */
export async function removeQueueConcurrencyLimits(
environment: AuthenticatedEnvironment,
queueName: string
) {
await Promise.allSettled([
marqs?.removeQueueConcurrencyLimits(environment, queueName),
engine.runQueue.removeQueueConcurrencyLimits(environment, queueName),
]);
}
/** Updates the rate limit configuration for a queue in Redis */
export async function updateQueueRateLimitConfig(
environment: AuthenticatedEnvironment,
queueName: string,
config: QueueRateLimitConfig
) {
await engine.runQueue.setQueueRateLimitConfig(environment, queueName, config);
}
/** Removes the rate limit configuration for a queue from Redis */
export async function removeQueueRateLimitConfig(
environment: AuthenticatedEnvironment,
queueName: string
) {
await engine.runQueue.removeQueueRateLimitConfig(environment, queueName);
}