5 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
namespace Quartz
namespace Quartz.Impl
val schedulerFactory : StdSchedulerFactory

Full name: Script.schedulerFactory
Multiple items
type StdSchedulerFactory =
  new : unit -> StdSchedulerFactory + 1 overload
  member AllSchedulers : ICollection<IScheduler>
  member GetScheduler : unit -> IScheduler + 1 overload
  member Initialize : unit -> unit + 1 overload
  static val ConfigurationSectionName : string
  static val PropertiesFile : string
  static val PropertySchedulerInstanceName : string
  static val PropertySchedulerInstanceId : string
  static val PropertySchedulerInstanceIdGeneratorPrefix : string
  static val PropertySchedulerInstanceIdGeneratorType : string
  ...

Full name: Quartz.Impl.StdSchedulerFactory

--------------------
StdSchedulerFactory() : unit
StdSchedulerFactory(props: Collections.Specialized.NameValueCollection) : unit
val scheduler : IScheduler

Full name: Script.scheduler
StdSchedulerFactory.GetScheduler() : IScheduler
StdSchedulerFactory.GetScheduler(schedName: string) : IScheduler
IScheduler.Start() : unit
Multiple items
namespace Quartz.Job

--------------------
type Job =
  interface IJob
  new : unit -> Job

Full name: Script.Job

--------------------
new : unit -> Job
type IJob =
  member Execute : context:IJobExecutionContext -> unit

Full name: Quartz.IJob
val x : Job
override Job.Execute : context:IJobExecutionContext -> unit

Full name: Script.Job.Execute
val context : IJobExecutionContext
type IJobExecutionContext =
  member Calendar : ICalendar
  member FireInstanceId : string
  member FireTimeUtc : Nullable<DateTimeOffset>
  member Get : key:obj -> obj
  member JobDetail : IJobDetail
  member JobInstance : IJob
  member JobRunTime : TimeSpan
  member MergedJobDataMap : JobDataMap
  member NextFireTimeUtc : Nullable<DateTimeOffset>
  member PreviousFireTimeUtc : Nullable<DateTimeOffset>
  ...

Full name: Quartz.IJobExecutionContext
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 : IJobDetail

Full name: Script.job
type JobBuilder =
  member Build : unit -> IJobDetail
  member OfType<'T> : unit -> JobBuilder + 1 overload
  member RequestRecovery : unit -> JobBuilder + 1 overload
  member SetJobData : newJobDataMap:JobDataMap -> JobBuilder
  member StoreDurably : unit -> JobBuilder + 1 overload
  member UsingJobData : newJobDataMap:JobDataMap -> JobBuilder + 6 overloads
  member WithDescription : description:string -> JobBuilder
  member WithIdentity : name:string -> JobBuilder + 2 overloads
  static member Create : unit -> JobBuilder + 2 overloads

Full name: Quartz.JobBuilder
JobBuilder.Create<'T (requires 'T :> IJob)>() : JobBuilder
JobBuilder.Create() : JobBuilder
JobBuilder.Create(jobType: Type) : JobBuilder
val trigger : ITrigger

Full name: Script.trigger
type TriggerBuilder =
  member Build : unit -> ITrigger
  member EndAt : endTimeUtc:Nullable<DateTimeOffset> -> TriggerBuilder
  member ForJob : jobKey:JobKey -> TriggerBuilder + 3 overloads
  member ModifiedByCalendar : calendarName:string -> TriggerBuilder
  member StartAt : startTimeUtc:DateTimeOffset -> TriggerBuilder
  member StartNow : unit -> TriggerBuilder
  member UsingJobData : newJobDataMap:JobDataMap -> TriggerBuilder + 7 overloads
  member WithDescription : description:string -> TriggerBuilder
  member WithIdentity : name:string -> TriggerBuilder + 2 overloads
  member WithPriority : priority:int -> TriggerBuilder
  ...

Full name: Quartz.TriggerBuilder
TriggerBuilder.Create() : TriggerBuilder
val x : SimpleScheduleBuilder
SimpleScheduleBuilder.WithIntervalInSeconds(seconds: int) : SimpleScheduleBuilder
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
IScheduler.ScheduleJob(trigger: ITrigger) : DateTimeOffset
IScheduler.ScheduleJob(jobDetail: IJobDetail, trigger: ITrigger) : DateTimeOffset
IScheduler.ScheduleJob(jobDetail: IJobDetail, triggersForJob: Collection.ISet<ITrigger>, replace: bool) : unit

More information

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