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
21 changes: 21 additions & 0 deletions apps/server/src/background/BackgroundPolicy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Coder: VCS polling is already scoped to browser subscription demand. With no
// client activity leases or host power monitor, scope work is always allowed.
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";

export interface BackgroundScope {
readonly type: "vcs-status";
readonly cwd: string;
}

export class BackgroundPolicy extends Context.Service<
BackgroundPolicy,
{
readonly shouldRunScopeWork: (scope: BackgroundScope) => Effect.Effect<boolean>;
}
>()("t3/background/BackgroundPolicy") {}

export const layer = Layer.succeed(BackgroundPolicy, {
shouldRunScopeWork: () => Effect.succeed(true),
});
25 changes: 22 additions & 3 deletions apps/server/src/coderRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import * as ServerConfig from "./config.ts";
import * as CheckpointDiffQuery from "./checkpointing/CheckpointDiffQuery.ts";
import * as CheckpointStore from "./checkpointing/CheckpointStore.ts";
import * as CoderEnvironment from "./coderEnvironment.ts";
import * as CoderVcsStatus from "./coderVcsStatus.ts";
import * as VcsStatusBroadcaster from "./vcs/VcsStatusBroadcaster.ts";
import * as BackgroundPolicy from "./background/BackgroundPolicy.ts";
import * as GitManager from "./git/GitManager.ts";
import * as GitWorkflowService from "./git/GitWorkflowService.ts";
import * as PullRequestProviderRegistry from "./pullRequest/PullRequestProviderRegistry.ts";
import * as PullRequestService from "./pullRequest/PullRequestService.ts";
Expand Down Expand Up @@ -130,13 +132,20 @@ const CoderProjectSetupScriptRunnerLive = ProjectSetupScriptRunner.layer.pipe(
Layer.provideMerge(CoderTerminalLive),
);

const CoderGitWorkflowLive = GitWorkflowService.layer.pipe(
const CoderGitManagerLive = GitManager.layer.pipe(
Layer.provide(SqlitePersistenceLayerLive),
Layer.provideMerge(GitVcsDriver.layer),
Layer.provideMerge(CoderSourceControlLive),
Layer.provideMerge(CoderTextGenerationLive),
Layer.provideMerge(CoderSettingsLive),
Layer.provideMerge(CoderProjectSetupScriptRunnerLive),
Layer.provideMerge(CoderProviderInstancesLive),
);

const CoderGitWorkflowLive = GitWorkflowService.layer.pipe(
Layer.provideMerge(CoderGitManagerLive),
Layer.provideMerge(GitVcsDriver.layer),
Layer.provideMerge(CoderVcsDriverRegistryLive),
);

const CoderSourceControlRepositoriesLive = SourceControlRepositoryService.layer.pipe(
Expand All @@ -152,7 +161,17 @@ const CoderVcsLive = Layer.mergeAll(
CoderGitWorkflowLive,
CoderSourceControlRepositoriesLive,
ProjectCloneTracker.layer.pipe(Layer.provide(CoderSourceControlRepositoriesLive)),
CoderVcsStatus.layer.pipe(Layer.provide(CoderGitWorkflowLive)),
// Coder: provide the demand-only background policy and fork settings resolution.
VcsStatusBroadcaster.layer.pipe(
Layer.provide(CoderGitWorkflowLive),
Layer.provide(BackgroundPolicy.layer),
Layer.provide(
VcsStatusBroadcaster.autoPullPolicyLayer.pipe(
Layer.provide(CoderOrchestrationLayerLive),
Layer.provide(CoderSettingsLive),
),
),
),
ReviewService.layer.pipe(
Layer.provideMerge(GitVcsDriver.layer),
Layer.provideMerge(CoderVcsDriverRegistryLive),
Expand Down
Loading