Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('mirror sweep activities', () => {
})
afterEach(() => vi.useRealTimers())

it('mirrors the most active candidates up to the limit, five at a time, logging every skip', async () => {
it('mirrors the most active candidates until the limit is mirrored, refilling skips, five at a time, logging every skip', async () => {
mocks.listUnmirroredNangoRepos.mockResolvedValue(
['r1', 'r2', 'r3', 'r4', 'r5', 'r6', 'r7', 'r8'].map(repo),
)
Expand All @@ -99,7 +99,7 @@ describe('mirror sweep activities', () => {
: { outcome: 'mirrored', unitsInserted: 8 }
})

await expect(mirrorBatch(7)).resolves.toEqual({
await expect(mirrorBatch(5)).resolves.toEqual({
candidates: 8,
attempted: 7,
mirrored: 5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
type IMirrorSweepSummary,
MIRROR_RESOLVE_CONCURRENCY,
type MirrorBatchResult,
chunk,
mirrorSince,
orderMirrorCandidates,
} from '../mirrorSweep'
Expand All @@ -28,15 +27,20 @@ const HEARTBEAT_INTERVAL_MS = 30_000
async function mirrorCandidates(
qx: QueryExecutor,
candidates: IMirrorCandidate[],
limit: number,
since: string,
result: MirrorBatchResult,
cancellation: AbortSignal,
): Promise<void> {
try {
for (const group of chunk(candidates, MIRROR_RESOLVE_CONCURRENCY)) {
let next = 0
while (result.mirrored < limit && next < candidates.length) {
if (cancellation.aborted) {
throw new Error('mirror batch cancelled')
}
const groupSize = Math.min(MIRROR_RESOLVE_CONCURRENCY, limit - result.mirrored)
const group = candidates.slice(next, next + groupSize)
next += group.length
const outcomes = await Promise.all(group.map((candidate) => mirrorRepo(qx, candidate, since)))
result.attempted += group.length
outcomes.forEach((outcome, i) => {
Expand Down Expand Up @@ -94,7 +98,8 @@ export async function mirrorBatch(limit: number): Promise<MirrorBatchResult> {
await initNangoCloudClient()
await mirrorCandidates(
qx,
ordered.slice(0, limit),
ordered,
limit,
mirrorSince(now),
result,
activityContext.cancellationSignal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function scheduleMirrorSweep(): Promise<void> {
type: 'startWorkflow',
workflowType: mirrorSweep,
taskQueue: 'connectors',
args: [{ batchSize: 1000, shadowCap: 5000 }],
args: [{ batchSize: 2500, shadowCap: 5000 }],
workflowExecutionTimeout: '2 hours',
},
})
Expand Down
Loading