From 2da8b5d2dfb2ced768f6e30eee7f00ff1cb898e1 Mon Sep 17 00:00:00 2001 From: Devon Burriss Date: Thu, 13 Feb 2025 07:01:43 +0100 Subject: [PATCH 1/2] Example proposal --- src/Farmer/Builders/Builders.WebApp.fs | 27 ++++++++++++++++++++++++-- src/Tests/WebApp.fs | 11 +++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/Farmer/Builders/Builders.WebApp.fs b/src/Farmer/Builders/Builders.WebApp.fs index 99957c590..a35216527 100644 --- a/src/Farmer/Builders/Builders.WebApp.fs +++ b/src/Farmer/Builders/Builders.WebApp.fs @@ -183,8 +183,8 @@ type SlotBuilder() = member this.AddKeyVaultIdentity(state: SlotConfig, identity: UserAssignedIdentityConfig) = this.AddKeyVaultIdentity(state, identity.UserAssignedIdentity) - [] /// Adds an AppSetting to this deployment slot + [] member this.AddSetting(state, key, value) : SlotConfig = { state with AppSettings = state.AppSettings.Add(key, value) @@ -947,6 +947,24 @@ type WebAppBuilder() = VirtualApplications = Map [] FunctionAppScaleLimit = None } + member __.Combine (currentValueFromYield: WebAppConfig, accumulatorFromDelay: WebAppConfig) = + System.Console.WriteLine($"currentValueFromYield: {currentValueFromYield.CommonWebConfig.AlwaysOn}") + System.Console.WriteLine($"accumulatorFromDelay: {accumulatorFromDelay.CommonWebConfig.AlwaysOn}") + { currentValueFromYield with + WebAppConfig.CommonWebConfig.AlwaysOn = false//accumulatorFromDelay.CommonWebConfig.AlwaysOn + } + + member this.For(state: WebAppConfig , f: unit -> WebAppConfig) = + let delayed = f() + this.Combine(state, delayed) + + member x.Zero() = + let v = x.Yield() + System.Console.WriteLine($"Zero {v.CommonWebConfig.AlwaysOn}") + v + // [] + // member _.eef(cond, thenExpr, elseExpr) = + // if cond then thenExpr() else elseExpr() member _.Run(state: WebAppConfig) = if state.Name.ResourceName = ResourceName.Empty then @@ -1560,6 +1578,11 @@ module Extensions = member this.AlwaysOn(state: 'T) = { this.Get state with AlwaysOn = true } |> this.Wrap state + /// Sets "Always On" flag + [] + member this.AlwaysOn(state: 'T, value: bool) = + { this.Get state with AlwaysOn = value } |> this.Wrap state + ///Chooses the bitness (32 or 64) of the worker process [] member this.WorkerProcess(state: 'T, bitness) = @@ -1652,8 +1675,8 @@ module Extensions = member this.FTPState(state: 'T, ftpState: FTPState) = this.Map state (fun x -> { x with FTPState = Some ftpState }) - [] /// Specifies the path Azure load balancers will ping to check for unhealthy instances. + [] member this.HealthCheckPath(state: 'T, healthCheckPath: string) = this.Map state (fun x -> { x with diff --git a/src/Tests/WebApp.fs b/src/Tests/WebApp.fs index e7aaedf7a..b0bfe88a1 100644 --- a/src/Tests/WebApp.fs +++ b/src/Tests/WebApp.fs @@ -675,6 +675,7 @@ let tests = Expect.isEmpty wa.SiteConfig.AppSettings "Should be no settings" } + test "Supports always on" { let template = webApp { name "web" @@ -687,6 +688,16 @@ let tests = Expect.equal w.SiteConfig.AlwaysOn (Nullable false) "always on should be false by default" } + test "Supports conditional always on" { + let expected = false + let template = webApp { + name "web" + always_on expected + } + + Expect.equal template.CommonWebConfig.AlwaysOn expected $"AlwaysOn should be {expected}" + } + test "Supports 32 and 64 bit worker processes" { let site: Site = webApp { name "web" } |> getResourceAtIndex 3 Expect.equal site.SiteConfig.Use32BitWorkerProcess (Nullable()) "Default worker process" From 0e8ffa174905642c4082a56acda2e76721a9f396 Mon Sep 17 00:00:00 2001 From: Devon Burriss Date: Thu, 13 Feb 2025 07:24:46 +0100 Subject: [PATCH 2/2] Cleanup --- src/Farmer/Builders/Builders.WebApp.fs | 28 +++----------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/src/Farmer/Builders/Builders.WebApp.fs b/src/Farmer/Builders/Builders.WebApp.fs index a35216527..d0673d070 100644 --- a/src/Farmer/Builders/Builders.WebApp.fs +++ b/src/Farmer/Builders/Builders.WebApp.fs @@ -947,24 +947,6 @@ type WebAppBuilder() = VirtualApplications = Map [] FunctionAppScaleLimit = None } - member __.Combine (currentValueFromYield: WebAppConfig, accumulatorFromDelay: WebAppConfig) = - System.Console.WriteLine($"currentValueFromYield: {currentValueFromYield.CommonWebConfig.AlwaysOn}") - System.Console.WriteLine($"accumulatorFromDelay: {accumulatorFromDelay.CommonWebConfig.AlwaysOn}") - { currentValueFromYield with - WebAppConfig.CommonWebConfig.AlwaysOn = false//accumulatorFromDelay.CommonWebConfig.AlwaysOn - } - - member this.For(state: WebAppConfig , f: unit -> WebAppConfig) = - let delayed = f() - this.Combine(state, delayed) - - member x.Zero() = - let v = x.Yield() - System.Console.WriteLine($"Zero {v.CommonWebConfig.AlwaysOn}") - v - // [] - // member _.eef(cond, thenExpr, elseExpr) = - // if cond then thenExpr() else elseExpr() member _.Run(state: WebAppConfig) = if state.Name.ResourceName = ResourceName.Empty then @@ -1575,13 +1557,9 @@ module Extensions = /// Sets "Always On" flag [] - member this.AlwaysOn(state: 'T) = - { this.Get state with AlwaysOn = true } |> this.Wrap state - - /// Sets "Always On" flag - [] - member this.AlwaysOn(state: 'T, value: bool) = - { this.Get state with AlwaysOn = value } |> this.Wrap state + member this.AlwaysOn(state: 'T, ?value: bool) = + let v = defaultArg value true + { this.Get state with AlwaysOn = v } |> this.Wrap state ///Chooses the bitness (32 or 64) of the worker process []