Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kentcdodds/lineage

src/backfill-continue.ts

27 lines · 880 B · TypeScript
import { workflows } from 'kody:runtime'
import backfill from './backfill.ts'

/**
 * Keep backfilling countable commits until the tracked branch is fully stored.
 * Each run ingests one batch, then enqueues the next batch when history remains.
 *
 * @returns The batch that just finished and whether another run was queued
 *
 * @example
 * import continueBackfill from 'kody:@kentcdodds/lineage/backfill-continue'
 *
 * const progress = await continueBackfill()
 */
export default async function continueBackfill() {
	const result = await backfill({ limit: 80, deadlineMs: 55_000 })
	let continued = false
	if (!result.done) {
		await workflows.create({
			exportName: './backfill-continue',
			params: {},
			idempotencyKey: `lineage:backfill:${result.ingest.storedCommits}:${result.ingest.newest?.sha ?? 'none'}`,
		})
		continued = true
	}
	return { ...result, continued }
}