Skip to content

Commit

Permalink
Major overhaul for new data model of events from Sessionize
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpowell committed Jul 9, 2019
1 parent 4de8cda commit 7a6e309
Show file tree
Hide file tree
Showing 14 changed files with 364 additions and 494 deletions.
273 changes: 0 additions & 273 deletions DDDApi.Functions/.azurefunctions/swagger/swagger.json

This file was deleted.

18 changes: 10 additions & 8 deletions DDDApi.Functions/DDDApi.Functions.fsproj
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
Expand All @@ -7,6 +7,10 @@
<ProjectReference Include="..\DDDApi\DDDApi.fsproj" />
</ItemGroup>
<ItemGroup>
<Compile Include="v1\DocumentationFunctions.fs" />
<Compile Include="v1\AgendaFunctions.fs" />
<Compile Include="v1\VotingFunctions.fs" />
<Compile Include="v1\SessionFunctions.fs" />
<Content Include="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand All @@ -16,22 +20,20 @@
<!-- <Content Include="proxies.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> -->
<Content Include=".azurefunctions/swagger/swagger.json">
<Content Include=".azurefunctions\swagger\swagger-v1.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Compile Include="azureTableUtils.fs" />
<Compile Include="SessionFunctions.fs" />
<Compile Include="SessionizeFunctions.fs" />
<Compile Include="VotingFunctions.fs" />
<Compile Include="DocumentationFunctions.fs" />
<Compile Include="AgendaFunctions.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FSharp.Azure.Storage" Version="3.0.0" />
<PackageReference Include="FSharp.Azure.Storage" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.1.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="1.7.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.6" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.28" />
<PackageReference Include="TaskBuilder.fs" Version="2.1.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="v2\" />
</ItemGroup>
</Project>
43 changes: 29 additions & 14 deletions DDDApi.Functions/SessionizeFunctions.fs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,56 @@ open Microsoft.Extensions.Configuration
open Microsoft.Azure.WebJobs
open Microsoft.WindowsAzure.Storage.Table
open DDDApi
open DDDApi.azureTableUtils
open DDDApi.SessionizeApi
open FSharp.Azure.Storage.Table
open Microsoft.Extensions.Logging

module SessionizeFunctions =
[<FunctionName("Download_Sessionzie_data")>]
let downloadSessionize([<TimerTrigger("0 5 * * * *")>]timer: TimerInfo,
[<Table("Session")>]sessionsSource: CloudTable,
context: ExecutionContext,
log: ILogger) =
let downloadSessionize ([<TimerTrigger("0 0 * * * *")>] timer: TimerInfo)
([<Table("Session", Connection = "EventStorage")>] sessionsSource: CloudTable)
([<Table("Presenter", Connection = "EventStorage")>] speakersSource: CloudTable)
(context: ExecutionContext)
(log: ILogger) =

let config = (ConfigurationBuilder())
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", true, true)
.AddEnvironmentVariables()
.Build()

let apiKey = config.["Sessionize.ApiKey"]
let apiKey = config.["Sessionize:ApiKey"]
async {
let! sessionize = downloadSessionize apiKey

let makeSession' = makeSession sessionize.Speakers sessionize.Categories
let makeSession' = makeSession sessionize.Categories sessionize.Questions

let remoteSessions = sessionize.Sessions
|> Array.map makeSession'
|> Array.map makeSession'

let existingSessions = Query.all<SessionV2>
|> Query.where <@ fun s _ -> s.EventYear = "2019" @>
|> fromTableToClient sessionsSource
|> Seq.map(fun (s, _) -> s)

let _ = addNewSessions log remoteSessions existingSessions sessionsSource
let _ = updateSessions log remoteSessions existingSessions sessionsSource

let existingSessions = Query.all<Session>
|> Query.where <@ fun _ s -> s.PartitionKey = "Session-2018" @>
|> fromTable sessionsSource.ServiceClient sessionsSource.Name
let existingSpeakers = Query.all<Presenter>
|> Query.where<@ fun s _ -> s.EventYear = "2019" @>
|> fromTableToClient speakersSource
|> Seq.map(fun (s, _) -> s)

let remoteSpeakers = remoteSessions
|> Array.map (makeSpeakers sessionize.Speakers sessionize.Categories sessionize.Questions)
|> Array.concat

(addNewSessions log remoteSessions existingSessions sessionsSource) |> ignore
(updateSessions log remoteSessions existingSessions sessionsSource) |> ignore
let _ = addNewSpeakers log remoteSpeakers existingSpeakers speakersSource
let _ = updateSpeakers log remoteSpeakers existingSpeakers speakersSource

log.LogInformation("Writing to queue")

return ignore
} |> Async.StartAsTask
return ignore()
}
|> Async.RunSynchronously
Loading

0 comments on commit 7a6e309

Please sign in to comment.