1 people like it.

Quartz Job Scheduling

A simple example showing how to use Quartz.NET, an open source job scheduling system, with FSharp.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
open System
open Quartz
open Quartz.Impl

let schedulerFactory = StdSchedulerFactory()
let scheduler = schedulerFactory.GetScheduler()
scheduler.Start()

type Job () =

    interface IJob with

        member x.Execute(context: IJobExecutionContext) =
            Console.WriteLine(DateTime.Now)


let job = JobBuilder.Create<Job>().Build()

let trigger =
    TriggerBuilder.Create()
        .WithSimpleSchedule(fun x ->
            x.WithIntervalInSeconds(1).RepeatForever() |> ignore)
        .Build()

scheduler.ScheduleJob(job, trigger) |> ignore
//scheduler.Shutdown()

// Output:
// 09/10/2012 11:08:03
// 09/10/2012 11:08:04
// 09/10/2012 11:08:05
// 09/10/2012 11:08:06
// 09/10/2012 11:08:07
// 09/10/2012 11:08:08
// 09/10/2012 11:08:09
// 09/10/2012 11:08:10
// 09/10/2012 11:08:11
// 09/10/2012 11:08:12
// ...
namespace System
val schedulerFactory : obj

Full name: Script.schedulerFactory
val scheduler : obj

Full name: Script.scheduler
Multiple items
type Job =
  interface obj
  new : unit -> Job
  override Execute : context:'a -> unit

Full name: Script.Job

--------------------
new : unit -> Job
val x : Job
override Job.Execute : context:'a -> unit

Full name: Script.Job.Execute
val context : 'a
type Console =
  static member BackgroundColor : ConsoleColor with get, set
  static member Beep : unit -> unit + 1 overload
  static member BufferHeight : int with get, set
  static member BufferWidth : int with get, set
  static member CapsLock : bool
  static member Clear : unit -> unit
  static member CursorLeft : int with get, set
  static member CursorSize : int with get, set
  static member CursorTop : int with get, set
  static member CursorVisible : bool with get, set
  ...

Full name: System.Console
Console.WriteLine() : unit
   (+0 other overloads)
Console.WriteLine(value: string) : unit
   (+0 other overloads)
Console.WriteLine(value: obj) : unit
   (+0 other overloads)
Console.WriteLine(value: uint64) : unit
   (+0 other overloads)
Console.WriteLine(value: int64) : unit
   (+0 other overloads)
Console.WriteLine(value: uint32) : unit
   (+0 other overloads)
Console.WriteLine(value: int) : unit
   (+0 other overloads)
Console.WriteLine(value: float32) : unit
   (+0 other overloads)
Console.WriteLine(value: float) : unit
   (+0 other overloads)
Console.WriteLine(value: decimal) : unit
   (+0 other overloads)
Multiple items
type DateTime =
  struct
    new : ticks:int64 -> DateTime + 10 overloads
    member Add : value:TimeSpan -> DateTime
    member AddDays : value:float -> DateTime
    member AddHours : value:float -> DateTime
    member AddMilliseconds : value:float -> DateTime
    member AddMinutes : value:float -> DateTime
    member AddMonths : months:int -> DateTime
    member AddSeconds : value:float -> DateTime
    member AddTicks : value:int64 -> DateTime
    member AddYears : value:int -> DateTime
    ...
  end

Full name: System.DateTime

--------------------
DateTime()
   (+0 other overloads)
DateTime(ticks: int64) : unit
   (+0 other overloads)
DateTime(ticks: int64, kind: DateTimeKind) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, calendar: Globalization.Calendar) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, kind: DateTimeKind) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, calendar: Globalization.Calendar) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, kind: DateTimeKind) : unit
   (+0 other overloads)
property DateTime.Now: DateTime
val job : obj

Full name: Script.job
val trigger : obj

Full name: Script.trigger
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore

More information

Link:http://fssnip.net/ec
Posted:3 years ago
Author:Taha Hachana
Tags: fsharp , quartz