Skip to content
Draft
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
107 changes: 107 additions & 0 deletions src/ofw/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Public OpenFlyWheel harness API."""

from pathlib import Path
from threading import Event

from langfuse import (
Langfuse,
Expand Down Expand Up @@ -147,6 +148,50 @@
VerifierResult,
VerifierVerdict,
)
from ofw.scheduler import (
AutomationPolicy as SchedulerAutomationPolicy,
)
from ofw.scheduler import (
BlockerCode,
BudgetStatus,
Dependency,
DependencyMode,
EvidenceOrigin,
EvidenceReader,
FailureDisposition,
Heartbeat,
HeartbeatEvidence,
HeartbeatOwner,
HeartbeatReport,
JobContext,
JobExecution,
JobExecutionError,
JobHandler,
JobId,
JobKind,
JobLease,
JobResult,
JobSpec,
JobState,
Money,
QuietHours,
ReconcileReport,
ResultId,
ScheduledJob,
SchedulerDaemon,
SchedulerError,
SchedulerErrorCode,
SourceWindowId,
StageBudgets,
Worker,
WorkerId,
)
from ofw.scheduler import (
LocalScheduler as SQLiteScheduler,
)

AutomationPolicy = SchedulerAutomationPolicy
LocalScheduler = SQLiteScheduler


class _OfwNamespace:
Expand Down Expand Up @@ -176,6 +221,11 @@ class _OfwNamespace:
CandidatePolicy = CandidatePolicy
CandidateBuilder = CandidateBuilder
FitPolicy = FitPolicy
AutomationPolicy = SchedulerAutomationPolicy
LocalScheduler = SQLiteScheduler
Money = Money
QuietHours = QuietHours
StageBudgets = StageBudgets

def editable(self, path: Path) -> EditableFile:
return editable(path)
Expand All @@ -189,6 +239,28 @@ def collect(
) -> CollectionResult:
return collect(revision, window=window, store_path=store_path)

def serve(
self,
harnesses: tuple[Harness, ...],
policy: SchedulerAutomationPolicy,
evidence: EvidenceReader,
stop: Event,
*,
store_path: Path,
owner: HeartbeatOwner,
) -> None:
revisions: tuple[HarnessRevisionId, ...] = ()
for harness in harnesses:
revision = harness.current_revision
if revision is None:
raise SchedulerError(SchedulerErrorCode.STALE_HARNESS, harness.name)
revisions = (*revisions, revision.id)
scheduler = SQLiteScheduler(store_path, policy)
try:
SchedulerDaemon(scheduler, owner, revisions, evidence).serve(stop)
finally:
scheduler.close()

def search_observation_content(
self,
collection: CollectionResult,
Expand Down Expand Up @@ -223,13 +295,16 @@ def read_snapshot_content(

__all__ = [
"AssetAccess",
"AutomationPolicy",
"Baseline",
"BenchmarkError",
"BenchmarkErrorCode",
"BenchmarkPolicy",
"BenchmarkResult",
"BenchmarkRunner",
"BenchmarkStatus",
"BlockerCode",
"BudgetStatus",
"CandidateBuilder",
"CandidateError",
"CandidateErrorCode",
Expand Down Expand Up @@ -260,13 +335,18 @@ def read_snapshot_content(
"DataLicense",
"DiagnosisError",
"DiagnosisErrorCode",
"Dependency",
"DependencyMode",
"EditableFile",
"EvidenceAnchor",
"EvidenceAnchorKind",
"EvidenceOrigin",
"EvidenceReader",
"ExportBundle",
"ExportPartition",
"ExportPolicy",
"FailureCluster",
"FailureDisposition",
"FileEdit",
"FitCampaign",
"FitError",
Expand All @@ -281,6 +361,10 @@ def read_snapshot_content(
"HarnessRevision",
"HarnessRevisionId",
"HarnessValidationError",
"Heartbeat",
"HeartbeatEvidence",
"HeartbeatOwner",
"HeartbeatReport",
"FunctionName",
"GateReason",
"Langfuse",
Expand All @@ -291,6 +375,7 @@ def read_snapshot_content(
"LeakageErrorCode",
"LineRange",
"LocalProcess",
"LocalScheduler",
"ModelFingerprint",
"ModuleName",
"Mine",
Expand All @@ -300,6 +385,7 @@ def read_snapshot_content(
"MiningPolicy",
"MechanismKey",
"MetricKind",
"Money",
"ObservationContent",
"ObservationContentField",
"ObservationContentHit",
Expand All @@ -315,13 +401,22 @@ def read_snapshot_content(
"PythonLoop",
"PythonDiagnoser",
"PythonVerifier",
"QuietHours",
"ReconcileReport",
"ResultId",
"RunErrorCode",
"RunResult",
"RunStatus",
"ScheduledJob",
"SchedulerDaemon",
"SchedulerError",
"SchedulerErrorCode",
"ScoreName",
"Sha256Digest",
"ServiceName",
"Severity",
"SourceWindowId",
"StageBudgets",
"SecretEnvironmentVariable",
"SnapshotContentReference",
"Subagent",
Expand All @@ -330,9 +425,21 @@ def read_snapshot_content(
"TracePartition",
"TraceQualityThreshold",
"TraceDiagnosis",
"JobContext",
"JobExecution",
"JobExecutionError",
"JobHandler",
"JobId",
"JobKind",
"JobLease",
"JobResult",
"JobSpec",
"JobState",
"VerifierResult",
"VerifierVerdict",
"WorkspaceFile",
"Worker",
"WorkerId",
"collect",
"editable",
"get_client",
Expand Down
Loading