diff --git a/Modules.Jobs/JobConfig.vb b/Modules.Jobs/JobConfig.vb index 9b086bd2..4c09a2cd 100644 --- a/Modules.Jobs/JobConfig.vb +++ b/Modules.Jobs/JobConfig.vb @@ -2,6 +2,7 @@ Public Class JobConfig Public Enabled As Boolean + Public StartImmediately As Boolean Public CronExpression As String Public Arguments As Dictionary(Of String, String) End Class \ No newline at end of file diff --git a/Modules.Jobs/JobConfigParser.vb b/Modules.Jobs/JobConfigParser.vb index 74a7cfd5..fff93541 100644 --- a/Modules.Jobs/JobConfigParser.vb +++ b/Modules.Jobs/JobConfigParser.vb @@ -2,7 +2,7 @@ Imports System.Text.RegularExpressions Public Class JobConfigParser - Private Shared JobOptionsRegex As New Regex("(?True|False)\|(?[\w\d\s,\?*-/]*)(?:\|(?(?:\w*::[^,\n]+,?)*))?") + Private Shared JobOptionsRegex As New Regex("(?True|False|Debug)\|(?[\w\d\s,\?*-/]*)(?:\|(?(?:\w*::[^,\n]+,?)*))?") Private Shared JobArgumentsRegex As New Regex("(?:(?:\w+::[^,\n]+,?)?)+") Private Const ARGS_ITEM_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) If oSplitOptions.Length = 3 Then - oOptions.Enabled = CBool(oSplitOptions(0)) + oOptions = ParseEnabled(oSplitOptions(0), oOptions) oOptions.CronExpression = oSplitOptions(1) oOptions.Arguments = ParseOptionalArguments(oSplitOptions(2)) ElseIf oSplitOptions.Length = 2 Then - oOptions.Enabled = CBool(oSplitOptions(0)) + oOptions = ParseEnabled(oSplitOptions(0), oOptions) oOptions.CronExpression = oSplitOptions(1) oOptions.Arguments = New Dictionary(Of String, String) Else @@ -38,6 +38,22 @@ Public Class JobConfigParser End If 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) Dim oArgsDictionary As New Dictionary(Of String, String) diff --git a/Service.JobRunner/JobRunner.vb b/Service.JobRunner/JobRunner.vb index f5fc2ba2..a6f920e6 100644 --- a/Service.JobRunner/JobRunner.vb +++ b/Service.JobRunner/JobRunner.vb @@ -1,5 +1,4 @@ Imports System.Collections.Specialized -Imports System.Text.RegularExpressions Imports DigitalData.Modules.Database Imports DigitalData.Modules.Jobs Imports DigitalData.Modules.Logging @@ -78,10 +77,22 @@ Public Class JobRunner If oJobConfig.Enabled Then Await _scheduler.ScheduleJob(oJobDetail, oTrigger) - _Logger.Info("Job {0} started.", JobName) + + _Logger.Info("Job {0} scheduled.", JobName) Else _Logger.Info("Job {0} is disabled.", JobName) 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 Public Async Sub [Stop]() @@ -92,7 +103,7 @@ Public Class JobRunner Private Class LogProvider Implements ILogProvider - Private _Logger As DigitalData.Modules.Logging.Logger + Private _Logger As Modules.Logging.Logger Public Sub New(Logger As DigitalData.Modules.Logging.Logger) MyBase.New()