-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup namespacing and dependency injection
- Loading branch information
Showing
6 changed files
with
67 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,19 @@ | ||
module DamoIoServer.App | ||
|
||
open System | ||
open DamoIoServer | ||
open DamoIoServer.SourcesRepository | ||
open FSharp.Control | ||
open Giraffe | ||
open Microsoft.Extensions.Logging | ||
|
||
open DamoIoServer.ArticlesRepository | ||
|
||
let private updatesSequence logger = | ||
asyncSeq { | ||
let tenMinutes = 10 * 1000 * 60 | ||
[<RequireQualifiedAccess>] | ||
module App = | ||
let handler: HttpHandler = | ||
choose | ||
[ GET >=> route "/" >=> redirectTo false "/About,Social,Blog" | ||
GET >=> routef "/%s" (ArticlesHandler.list ArticlesRepository.findAllBySources) | ||
setStatusCode 404 >=> text "Not Found" ] | ||
|
||
while true do | ||
let! newArticles = | ||
SourcesRepository.findAll () | ||
|> FeedsProcessor.processFeeds logger | ||
|> AsyncSeq.toListAsync | ||
|
||
yield newArticles | ||
|
||
do! Async.Sleep tenMinutes | ||
} | ||
|
||
let backgroundProcessing logger = | ||
AsyncSeq.iter ArticlesRepository.updateAll (updatesSequence logger) | ||
|
||
let handler: HttpHandler = | ||
choose | ||
[ GET >=> route "/" >=> redirectTo false "/About,Social,Blog" | ||
GET >=> routef "/%s" (ArticlesHandler.list ArticlesRepository.findAllBySources) | ||
setStatusCode 404 >=> text "Not Found" ] | ||
|
||
let errorHandler (ex: Exception) (logger: ILogger) : HttpHandler = | ||
logger.LogError(ex, "An unhandled exception has occurred while executing the request.") | ||
clearResponse >=> setStatusCode 500 >=> text ex.Message | ||
let errorHandler (ex: Exception) (logger: ILogger) : HttpHandler = | ||
logger.LogError(ex, "An unhandled exception has occurred while executing the request.") | ||
clearResponse >=> setStatusCode 500 >=> text ex.Message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
[<RequireQualifiedAccess>] | ||
module DamoIoServer.AppConfig | ||
|
||
open System.IO | ||
|
||
let serverPort = Env.varDefault "PORT" (always "9000") | ||
[<RequireQualifiedAccess>] | ||
module AppConfig = | ||
let serverPort = Env.varDefault "PORT" (always "9000") | ||
|
||
let contentRoot = Env.varDefault "CONTENT_ROOT" Directory.GetCurrentDirectory | ||
let contentRoot = Env.varDefault "CONTENT_ROOT" Directory.GetCurrentDirectory | ||
|
||
let assetMinificationDisabled = | ||
Env.var "DISABLE_MINIFIED_ASSETS" |> Option.hasValue "true" | ||
let assetMinificationDisabled = | ||
Env.var "DISABLE_MINIFIED_ASSETS" |> Option.hasValue "true" | ||
|
||
let assetMinificationEnabled = not assetMinificationDisabled | ||
let assetMinificationEnabled = not assetMinificationDisabled | ||
|
||
let enableExceptionPage = Env.var "ENABLE_EXCEPTION_PAGE" |> Option.hasValue "true" | ||
let enableExceptionPage = Env.var "ENABLE_EXCEPTION_PAGE" |> Option.hasValue "true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module DamoIoServer.BackgroundProcessor | ||
|
||
open FSharp.Control | ||
open Microsoft.Extensions.Logging | ||
|
||
open DamoIoServer.SourcesRepository | ||
open DamoIoServer.ArticlesRepository | ||
|
||
[<RequireQualifiedAccess>] | ||
type BackgroundProcessor(logger: ILogger, updateArticles: ArticlesRepository.UpdateArticles) = | ||
|
||
let updatesSequence () = | ||
asyncSeq { | ||
let tenMinutes = 10 * 1000 * 60 | ||
|
||
while true do | ||
let! newArticles = | ||
SourcesRepository.findAll () | ||
|> FeedsProcessor.processFeeds logger | ||
|> AsyncSeq.toListAsync | ||
|
||
yield newArticles | ||
|
||
do! Async.Sleep tenMinutes | ||
} | ||
|
||
member this.StartProcessing() = | ||
Async.Start(updatesSequence () |> AsyncSeq.iter updateArticles) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters