mirror of
https://github.com/whyour/qinglong.git
synced 2026-09-22 02:27:44 +08:00
feat(ql3): establish 3.0 incubation baseline
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import {
|
||||
assertRunDispatchCandidate,
|
||||
assertRunDispatchCandidatePageSize,
|
||||
type RunDispatchCandidate,
|
||||
} from './runDispatchCandidate';
|
||||
import {
|
||||
assertRunDispatchId,
|
||||
assertRunDispatchLeaseRecord,
|
||||
assertRunDispatchLeaseVersion,
|
||||
type RunDispatchLeaseRecord,
|
||||
} from './runDispatchLease';
|
||||
|
||||
export const MAX_RUN_DISPATCH_RECOVERY_PAGE_SIZE = 64;
|
||||
|
||||
export interface RunDispatchRecoveryCursor {
|
||||
expiresAtMs: number;
|
||||
attemptId: string;
|
||||
}
|
||||
|
||||
export interface RecoverableRunDispatch {
|
||||
candidate: RunDispatchCandidate;
|
||||
lease: RunDispatchLeaseRecord;
|
||||
}
|
||||
|
||||
export function assertRunDispatchRecoveryCursor(
|
||||
cursor: RunDispatchRecoveryCursor,
|
||||
): void {
|
||||
assertRunDispatchLeaseVersion('expiresAtMs', cursor.expiresAtMs);
|
||||
assertRunDispatchId('attemptId', cursor.attemptId);
|
||||
}
|
||||
|
||||
export function assertRecoverableRunDispatch(
|
||||
recovery: RecoverableRunDispatch,
|
||||
): void {
|
||||
if (!recovery || typeof recovery !== 'object' || Array.isArray(recovery)) {
|
||||
throw new TypeError('Recoverable Run dispatch must be an object');
|
||||
}
|
||||
assertRunDispatchCandidate(recovery.candidate);
|
||||
assertRunDispatchLeaseRecord(recovery.lease);
|
||||
if (
|
||||
recovery.lease.status !== 'leased' ||
|
||||
recovery.lease.runId !== recovery.candidate.runId ||
|
||||
recovery.lease.attemptId !== recovery.candidate.attemptId
|
||||
) {
|
||||
throw new TypeError(
|
||||
'Recoverable Run dispatch candidate and active lease do not match',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function assertRunDispatchRecoveryPageSize(limit: number): void {
|
||||
assertRunDispatchCandidatePageSize(limit);
|
||||
if (limit > MAX_RUN_DISPATCH_RECOVERY_PAGE_SIZE) {
|
||||
throw new RangeError(
|
||||
`Run dispatch recovery page size must not exceed ${MAX_RUN_DISPATCH_RECOVERY_PAGE_SIZE}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user