add service
This commit is contained in:
68
EnvelopeGenerator.Service/Scheduler.vb
Normal file
68
EnvelopeGenerator.Service/Scheduler.vb
Normal file
@@ -0,0 +1,68 @@
|
||||
Imports System.Collections.Specialized
|
||||
Imports DigitalData.Modules.Base
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports EnvelopeGenerator.Common.Jobs
|
||||
Imports Quartz
|
||||
|
||||
Public Class Scheduler
|
||||
Inherits BaseClass
|
||||
|
||||
Private Scheduler As IScheduler
|
||||
Private ConnectionString As String
|
||||
|
||||
Private Const JobName = "CertificateDocumentJob"
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pConnectionString As String)
|
||||
MyBase.New(pLogConfig)
|
||||
ConnectionString = pConnectionString
|
||||
End Sub
|
||||
|
||||
Public Async Function Start(pInterval As Integer) As Task
|
||||
Logger.Debug("Starting Scheduler..")
|
||||
|
||||
Dim oProperties As New NameValueCollection()
|
||||
|
||||
Scheduler = Await SchedulerBuilder.Create(oProperties).
|
||||
UseDefaultThreadPool(Sub(x) x.MaxConcurrency = 5).
|
||||
BuildScheduler()
|
||||
|
||||
Dim oJobKey = New JobKey(JobName)
|
||||
Dim oJobData = New JobDataMap() From {
|
||||
{Common.Constants.LOGCONFIG, LogConfig},
|
||||
{Common.Constants.DATABASE, ConnectionString}
|
||||
}
|
||||
|
||||
Logger.Debug("Initialized Job [{0}]", JobName)
|
||||
|
||||
Dim oJob As IJobDetail = JobBuilder.Create(Of CertificateDocumentJob).
|
||||
UsingJobData(oJobData).
|
||||
WithIdentity(oJobKey).
|
||||
Build()
|
||||
|
||||
Dim oTrigger As ITrigger = TriggerBuilder.Create().
|
||||
ForJob(oJobKey).
|
||||
WithIdentity($"{JobName}-trigger").
|
||||
WithSimpleSchedule(Sub(s) s.
|
||||
RepeatForever().
|
||||
WithIntervalInMinutes(pInterval)).
|
||||
Build()
|
||||
|
||||
Logger.Debug("Initialized Trigger")
|
||||
|
||||
Await Scheduler.ScheduleJob(oJob, oTrigger)
|
||||
|
||||
Logger.Debug("Job scheduled.")
|
||||
|
||||
Await Scheduler.Start()
|
||||
|
||||
Logger.Info("Scheduler started!")
|
||||
End Function
|
||||
|
||||
Public Async Function [Stop]() As Task
|
||||
Logger.Info("Stopping scheduler..")
|
||||
Await Scheduler.Shutdown()
|
||||
Logger.Info("Scheduler stopped!")
|
||||
End Function
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user