Skip to content

Instantly share code, notes, and snippets.

@AlexCuse
Created June 25, 2011 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexCuse/1046062 to your computer and use it in GitHub Desktop.
Save AlexCuse/1046062 to your computer and use it in GitHub Desktop.
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