Created
June 25, 2011 02:46
-
-
Save AlexCuse/1046062 to your computer and use it in GitHub Desktop.
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
type Service = //snip | |
member this.Run() = | |
let mutable retryCount = 0 | |
while retryCount < 10 do | |
//what to do on mono? Maybe setting up local log better | |
let errorCallback = | |
function(ex:System.Exception) -> this.EventLog.WriteEntry("error in BrewTelligence Indexing Service:\n\n" + ex.Message + "\n\n" + ex.StackTrace) | |
try | |
Indexer.Initialize() | |
let threads = | |
seq { | |
yield new Thread(new ThreadStart(fun () -> Indexer.Run<Recipe>(errorCallback))) | |
yield new Thread(new ThreadStart(fun () -> Indexer.Run<Malt>(errorCallback))) | |
yield new Thread(new ThreadStart(fun () -> Indexer.Run<Hop>(errorCallback))) | |
yield new Thread(new ThreadStart(fun () -> Indexer.Run<Yeast>(errorCallback))) | |
} |> List.ofSeq | |
threads |> List.iter (fun t -> t.Start()) | |
while threads |> List.forall (fun t -> t.IsAlive) do | |
Thread.Sleep 500 | |
Indexer.Shutdown() | |
with | |
| _ as ex -> errorCallback ex | |
Thread.Sleep 1000 | |
retryCount <- retryCount + 1 | |
//snip | |
module Indexer = | |
let Run<'T when 'T: not struct and 'T:null and 'T:equality> (errorCallback) = | |
try | |
indexActions<'T> | |
|> OptionSeq.unwrapAndDiscardEmpty | |
|> Seq.iter Async.RunSynchronously | |
|> ignore | |
with | |
| _ as ex -> errorCallback ex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment