import { env } from "cloudflare:workers";
import { ringJobDoorbells } from "./job-doorbell";
import { assertWithinQuota, QuotaExceededError } from "../metering/quota";
import { isScratchRepo } from "../sites/config";
import { numberVar } from "../limits";
import { repoDb } from "../scoped-db";
import { ownerRepoIds, repoOwnerId, runDb } from "./scope";
import { completeJob, isCloudJob, runnerStub } from "./jobs";
import type { WorkflowJobRow, WorkflowRunRow } from "./jobs";
import { gateJob } from "./deployments";
import { forkRunsAllowed, hasForkEligibleRunner } from "./runner-policy";
import { recompileJob } from "./recompile";
import { holdJobMinutes, releaseJobHold } from "./job-hold";
import { CLOUD_RUNS_ON_VALUES, cloudRunnerSize, cloudRunsOnPlaceholders, runnerWeightSql } from "./runner-sizes";
import type { CompiledJob } from "./compile";
import type { Conclusion } from "~/lib/types";
export type JobState = {
id: string;
key: string;
baseKey: string;
needs: string[];
runsOn: string[];
timeoutMinutes: number;
status: string;
conclusion: Conclusion | null;
cloud: boolean;
runIfOk: boolean;
runIfFailed: boolean;
row: WorkflowJobRow;
};
export type TickResult = { active: number; dispatched: number; deferred: number; gated: number; wakeAt: number | null };
const QUEUE_DEADLINE_MS = 24 * 60 * 60 * 1000;
const REVIEW_DEADLINE_MS = 72 * 60 * 60 * 1000;
const DAY_MS = 24 * 60 * 60 * 1000;
const MINUTE_MS = 60 * 1000;
const DEFAULT_JOBS_PER_OWNER = 4;
const DEFAULT_MINUTES_PER_DAY = 600;