Jobs: Add option to start jobs immediately
This commit is contained in:
parent
ffcfd017ce
commit
7327a9b2fa
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
Public Class JobConfig
|
Public Class JobConfig
|
||||||
Public Enabled As Boolean
|
Public Enabled As Boolean
|
||||||
|
Public StartImmediately As Boolean
|
||||||
Public CronExpression As String
|
Public CronExpression As String
|
||||||
Public Arguments As Dictionary(Of String, String)
|
Public Arguments As Dictionary(Of String, String)
|
||||||
End Class
|
End Class
|
||||||
@ -2,7 +2,7 @@
|
|||||||
Imports System.Text.RegularExpressions
|
Imports System.Text.RegularExpressions
|
||||||
|
|
||||||
Public Class JobConfigParser
|
Public Class JobConfigParser
|
||||||
Private Shared JobOptionsRegex As New Regex("(?<enabled>True|False)\|(?<cron>[\w\d\s,\?*-/]*)(?:\|(?<args>(?:\w*::[^,\n]+,?)*))?")
|
Private Shared JobOptionsRegex As New Regex("(?<enabled>True|False|Debug)\|(?<cron>[\w\d\s,\?*-/]*)(?:\|(?<args>(?:\w*::[^,\n]+,?)*))?")
|
||||||
Private Shared JobArgumentsRegex As New Regex("(?:(?:\w+::[^,\n]+,?)?)+")
|
Private Shared JobArgumentsRegex As New Regex("(?:(?:\w+::[^,\n]+,?)?)+")
|
||||||
Private Const ARGS_ITEM_DELIMITER As String = ","
|
Private Const ARGS_ITEM_DELIMITER As String = ","
|
||||||
Private Const ARGS_KEYVALUE_DELIMITER As String = "::"
|
Private Const ARGS_KEYVALUE_DELIMITER As String = "::"
|
||||||
@ -21,11 +21,11 @@ Public Class JobConfigParser
|
|||||||
Dim oSplitOptions As String() = ConfigString.Split(ARGS_LIST_DELIMITER)
|
Dim oSplitOptions As String() = ConfigString.Split(ARGS_LIST_DELIMITER)
|
||||||
|
|
||||||
If oSplitOptions.Length = 3 Then
|
If oSplitOptions.Length = 3 Then
|
||||||
oOptions.Enabled = CBool(oSplitOptions(0))
|
oOptions = ParseEnabled(oSplitOptions(0), oOptions)
|
||||||
oOptions.CronExpression = oSplitOptions(1)
|
oOptions.CronExpression = oSplitOptions(1)
|
||||||
oOptions.Arguments = ParseOptionalArguments(oSplitOptions(2))
|
oOptions.Arguments = ParseOptionalArguments(oSplitOptions(2))
|
||||||
ElseIf oSplitOptions.Length = 2 Then
|
ElseIf oSplitOptions.Length = 2 Then
|
||||||
oOptions.Enabled = CBool(oSplitOptions(0))
|
oOptions = ParseEnabled(oSplitOptions(0), oOptions)
|
||||||
oOptions.CronExpression = oSplitOptions(1)
|
oOptions.CronExpression = oSplitOptions(1)
|
||||||
oOptions.Arguments = New Dictionary(Of String, String)
|
oOptions.Arguments = New Dictionary(Of String, String)
|
||||||
Else
|
Else
|
||||||
@ -38,6 +38,22 @@ Public Class JobConfigParser
|
|||||||
End If
|
End If
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
Public Shared Function ParseEnabled(EnabledValue As String, Options As JobConfig) As JobConfig
|
||||||
|
Select Case EnabledValue
|
||||||
|
Case "True"
|
||||||
|
Options.Enabled = True
|
||||||
|
Options.StartImmediately = False
|
||||||
|
Case "Debug"
|
||||||
|
Options.Enabled = True
|
||||||
|
Options.StartImmediately = True
|
||||||
|
Case Else
|
||||||
|
Options.Enabled = False
|
||||||
|
Options.StartImmediately = False
|
||||||
|
End Select
|
||||||
|
|
||||||
|
Return Options
|
||||||
|
End Function
|
||||||
|
|
||||||
Private Shared Function ParseOptionalArguments(ArgsString As String) As Dictionary(Of String, String)
|
Private Shared Function ParseOptionalArguments(ArgsString As String) As Dictionary(Of String, String)
|
||||||
Dim oArgsDictionary As New Dictionary(Of String, String)
|
Dim oArgsDictionary As New Dictionary(Of String, String)
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
Imports System.Collections.Specialized
|
Imports System.Collections.Specialized
|
||||||
Imports System.Text.RegularExpressions
|
|
||||||
Imports DigitalData.Modules.Database
|
Imports DigitalData.Modules.Database
|
||||||
Imports DigitalData.Modules.Jobs
|
Imports DigitalData.Modules.Jobs
|
||||||
Imports DigitalData.Modules.Logging
|
Imports DigitalData.Modules.Logging
|
||||||
@ -78,10 +77,22 @@ Public Class JobRunner
|
|||||||
|
|
||||||
If oJobConfig.Enabled Then
|
If oJobConfig.Enabled Then
|
||||||
Await _scheduler.ScheduleJob(oJobDetail, oTrigger)
|
Await _scheduler.ScheduleJob(oJobDetail, oTrigger)
|
||||||
_Logger.Info("Job {0} started.", JobName)
|
|
||||||
|
_Logger.Info("Job {0} scheduled.", JobName)
|
||||||
Else
|
Else
|
||||||
_Logger.Info("Job {0} is disabled.", JobName)
|
_Logger.Info("Job {0} is disabled.", JobName)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
' If StartImmediately is True, start Job after 10 Seconds
|
||||||
|
If oJobConfig.StartImmediately Then
|
||||||
|
Dim oDebugTrigger = TriggerBuilder.Create().
|
||||||
|
WithIdentity(oTriggerIdentity & "-DEBUG").
|
||||||
|
StartAt(DateBuilder.FutureDate(10, IntervalUnit.Second)).
|
||||||
|
Build()
|
||||||
|
|
||||||
|
_Logger.Info("Job {0} will start in 10 Seconds.", JobName)
|
||||||
|
Await _scheduler.ScheduleJob(oJobDetail, oDebugTrigger)
|
||||||
|
End If
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Public Async Sub [Stop]()
|
Public Async Sub [Stop]()
|
||||||
@ -92,7 +103,7 @@ Public Class JobRunner
|
|||||||
Private Class LogProvider
|
Private Class LogProvider
|
||||||
Implements ILogProvider
|
Implements ILogProvider
|
||||||
|
|
||||||
Private _Logger As DigitalData.Modules.Logging.Logger
|
Private _Logger As Modules.Logging.Logger
|
||||||
|
|
||||||
Public Sub New(Logger As DigitalData.Modules.Logging.Logger)
|
Public Sub New(Logger As DigitalData.Modules.Logging.Logger)
|
||||||
MyBase.New()
|
MyBase.New()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user