"无法存储作业:无法存储作业:' QbBackupGroup.QbBackup',因为已存在此标识。"
我在干净的数据库(SQLCE)上第一次运行后的任何时间都得到这个。我已经搜索并找到了一些建议(例如here和here),但它们与运行Quartz.NET 而不是 TopShelf有关。
建议的代码基于标准的Quartz.NET架构(例如变量和值),但TopShelf的Quartz.NET代码都是代理。似乎没有什么可以直接翻译。
我的代码如下。
然而......所有这些......可能并不重要,因为我最终的目标是能够在运行时添加/删除作业/触发器而无需重新启动服务。这种硬编码设计可能甚至不适用,但我还没有想出如何运行运行程序位。
如果我可以通过这个,那么运行时位就是下一个。除非运行时位否定了对此的需要。捉-21。
请告知。
服务
Sub Main()
Dim oSchedule As Action(Of SimpleScheduleBuilder)
Dim oTrigger As Func(Of ITrigger)
Dim oDetail As Func(Of IJobDetail)
Dim oJob As Action(Of QuartzConfigurator)
oSchedule = Function(ScheduleBuilder) As SimpleScheduleBuilder
Return ScheduleBuilder.WithIntervalInSeconds(5).RepeatForever
End Function
oTrigger = Function() As ITrigger
Return TriggerBuilder.Create.WithIdentity(QbBackup.Job.Trigger, QbBackup.Job.Group).WithSimpleSchedule(oSchedule).Build
End Function
oDetail = Function()
Return JobBuilder.Create(Of QbBackup.Job).WithIdentity(QbBackup.Job.Name, QbBackup.Job.Group).Build
End Function
oJob = Function(Configurator As QuartzConfigurator)
Return Configurator.WithJob(oDetail).AddTrigger(oTrigger)
End Function
HostFactory.Run(Sub(Configurator)
Configurator.Service(Of Manager)(Sub(Service)
Service.ConstructUsing(Function(Factory) As ServiceControl
Return New Manager
End Function)
Service.WhenStarted(Function(Notifier, HostControl) As Boolean
Return Notifier.StartService(HostControl)
End Function)
Service.WhenStopped(Function(Notifier, HostControl) As Boolean
Return Notifier.StopService(HostControl)
End Function)
Service.ScheduleQuartzJob(oJob)
End Sub)
Configurator.SetDescription(SchedulerInfo.Description)
Configurator.SetServiceName(SchedulerInfo.Product)
Configurator.SetDisplayName(SchedulerInfo.Title)
Configurator.StartAutomatically()
Configurator.RunAsLocalSystem()
End Sub)
End Sub
作业:
Imports Common.Logging
Public Class Job
Implements IJob
Private Shared Logger As ILog = LogManager.GetLogger(GetType(Job))
Public Sub Execute(Context As IJobExecutionContext) Implements IJob.Execute
Try
Job.Logger.Info(Now.ToString)
Catch ex As Exception
Throw New JobExecutionException(ex.Message, ex)
End Try
End Sub
Public Shared ReadOnly Property Name As String
Get
Return QbBackupInfo.Product
End Get
End Property
Public Shared ReadOnly Property Trigger As String
Get
Return "{0}Trigger".ToFormat(Job.Name)
End Get
End Property
Public Shared ReadOnly Property Group As String
Get
Return "{0}Group".ToFormat(Job.Name)
End Get
End Property
End Class
App.config中:
<quartz>
<!-- Configure Scheduler -->
<add key="quartz.scheduler.instanceName" value="Scheduler" />
<add key="quartz.scheduler.instanceId" value="Scheduler" />
<!-- Configure Thread Pool -->
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
<add key="quartz.threadPool.threadCount" value="10" />
<add key="quartz.threadPool.threadPriority" value="Normal" />
<!-- Configure Job Store -->
<add key="quartz.jobStore.misfireThreshold" value="60000" />
<add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" />
<add key="quartz.jobStore.useProperties" value="true" />
<add key="quartz.jobStore.dataSource" value="default" />
<add key="quartz.jobStore.tablePrefix" value="QRTZ_" />
<add key="quartz.jobStore.lockHandler.type" value="Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz" />
<!-- Configure Data Source -->
<add key="quartz.dataSource.default.connectionString" value="Data Source=C:\ProgramData\Scheduler\Scheduler.sdf;Max Database Size=4091;Persist Security Info=False;" />
<add key="quartz.dataSource.default.provider" value="SqlServerCe-400" />
</quartz>
答案 0 :(得分:1)
作业组及其名称的组合是Quartz.Net中作业的唯一键。它们在所有工作中应该是独一无二的触发器也是如此。如果您确实需要运行多个相同类型的作业,则修复方法是更改每个作业的作业名称。您也可以只使用多个触发器创建一个作业。每个触发器都有自己的数据图,因此您可以在那里添加自定义信息。解决这个问题的一种方法是在作业的名称后附一个时间戳,以便它们都具有唯一的名称。