Scheduled Job Only Runs the First Time (should be every 24hrs.)

33 views
Skip to first unread message

Will Lingard

unread,
Mar 19, 2012, 1:08:20 PM3/19/12
to Quartz.NET
Hi Group,

My first post in here, hoping perhaps someone can help out a little.

I've started using Quartz recently and got things setup and working. I
can schedule and run a job, however when I setup the Trigger to run
every 24 hours, it runs on create and then never again.

My code below.... any help much appreciated; thanks.

Best Regards,

Will

==========================================================

''' <summary>
''' Schedule Local Job
''' </summary>
''' <param name="jobType"></param>
''' <param name="dataMap"></param>
''' <remarks></remarks>
Protected Sub ScheduleLocalJob(ByVal jobType As Type, ByVal
dataMap As JobDataMap, ByVal name As String, ByVal group As String,
Optional ByVal oneTimeJob As Boolean = False)

Try

Dim sf As ISchedulerFactory = New
StdSchedulerFactory()
Dim sched As IScheduler = sf.GetScheduler()

If sched.CheckExists(New JobKey(name, group)) Then
sched.DeleteJob(New JobKey(name, group))
End If

sched.Start()

Dim jobDetail As IJobDetail =
JobBuilder.Create().OfType(jobType).WithIdentity(New JobKey(name,
group)).UsingJobData(dataMap).StoreDurably().Build()

Dim trigger As ITrigger
If oneTimeJob Then
trigger =
TriggerBuilder.Create().ForJob(jobDetail).WithIdentity(New
TriggerKey(name,
group)).WithSchedule(SimpleScheduleBuilder.Create()).StartNow().Build()
Else
trigger =
TriggerBuilder.Create().ForJob(jobDetail).WithIdentity(New
TriggerKey(name,
group)).WithSchedule(SimpleScheduleBuilder.Create().WithIntervalInHours(24).RepeatForever()).StartNow().Build()
End If

sched.ScheduleJob(jobDetail, trigger)

Catch ex As Exception

DisplaySavedSuccessOrFail(False, ex.Message)

End Try

End Sub
'//-->

==========================================================

Nuno Maia

unread,
Mar 19, 2012, 6:03:07 PM3/19/12
to quar...@googlegroups.com
I think your issue is in scope of variable sched, use a Singleton
pattern for it.

> --
> You received this message because you are subscribed to the Google Groups "Quartz.NET" group.
> To post to this group, send email to quar...@googlegroups.com.
> To unsubscribe from this group, send email to quartznet+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/quartznet?hl=en.
>

Reply all
Reply to author
Forward
0 new messages