EnvelopeGenerator/EnvelopeGenerator.Service/Scheduler_Envelopetask_API.vb
TekH f699e5a9aa Refactor constant references across multiple files
Updated import statements and changed references from
`Domain.Constants` to `Value` in `APIEnvelopeJob.vb`,
`FinalizeDocumentJob.vb`, `HistoryModel.vb`, `EmailService.vb`,
and job scheduling files. This standardizes constant access
and improves code maintainability and readability.
2025-09-01 11:20:57 +02:00

71 lines
2.3 KiB
VB.net

Imports System.Collections.Specialized
Imports DigitalData.Modules.Base
Imports DigitalData.Modules.Logging
Imports EnvelopeGenerator.CommonServices.Jobs
Imports Quartz
Public Class Scheduler_Envelopetask_API
Inherits BaseClass
Private Scheduler As IScheduler
Private ReadOnly ConnectionString As String
Private Const JobName = "SendInvitationMailsAPI"
Public Sub New(pLogConfig As LogConfig, pConnectionString As String)
MyBase.New(pLogConfig)
ConnectionString = pConnectionString
Dim oLogProvider = New LogProvider(Logger)
Logging.LogProvider.SetCurrentLogProvider(oLogProvider)
End Sub
Public Async Function Start(pInterval As Integer) As Task
Try
Logger.Debug("Starting Scheduler SendMailsfromAPI..")
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 {
{Value.LOGCONFIG, LogConfig},
{Value.DATABASE, ConnectionString}
}
Logger.Debug("Initialized Job [{0}]", JobName)
Dim oJob As IJobDetail = JobBuilder.Create(Of APIEnvelopeJob).
UsingJobData(oJobData).
WithIdentity(oJobKey).
Build()
Dim oTrigger As ITrigger = TriggerBuilder.Create().
ForJob(oJobKey).
WithIdentity($"{JobName}-trigger").
WithSimpleSchedule(Sub(s) s.
RepeatForever().
WithIntervalInMinutes(pInterval)).
StartNow().
Build()
Logger.Debug($"{JobName}-trigger initialized")
Await Scheduler.ScheduleJob(oJob, oTrigger)
Logger.Debug($"{JobName}-scheduled")
Await Scheduler.Start()
Logger.Info($"{JobName}-started")
Catch ex As Exception
Logger.Error(ex)
End Try
End Function
Public Async Function [Stop]() As Task
Logger.Info("Stopping scheduler SendMailsfromAPI..")
Await Scheduler.Shutdown()
Logger.Info("Scheduler SendMailsfromAPI stopped!")
End Function
End Class