Skip to content

Instantly share code, notes, and snippets.

@punitganshani
Created July 18, 2015 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save punitganshani/36d451a5585a589e703b to your computer and use it in GitHub Desktop.
Save punitganshani/36d451a5585a589e703b to your computer and use it in GitHub Desktop.
Scheduling Background Tasks in ASP.NET using Quartz
using Quartz;
using Quartz.Impl;
namespace Tasks
{
public class MaintenanceJob : IJob
{
public void Execute(IJobExecutionContext context)
{
var ftpLocation = context.JobDetail.JobDataMap.Get("ftp.location");
// zip old log files
// delete the files once zip is completed
// sftp the zip to another location
}
}
public class Triggers
{
public static ITrigger TimeTrigger()
{
return TriggerBuilder.Create()
.WithDailyTimeIntervalSchedule
(s =>
s.WithIntervalInHours(24)
.OnEveryDay()
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(0, 0))
)
.Build();
}
public static ITrigger CRONTrigger()
{
return TriggerBuilder.Create()
.WithCronSchedule("At 8:00am every Monday through Friday", s => s.WithMisfireHandlingInstructionDoNothing())
.Build();
}
}
public class JobScheduler
{
public static void Start()
{
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
scheduler.Start();
IJobDetail job = JobBuilder.Create<MaintenanceJob>().Build();
job.JobDataMap.Add("ftp.location", "ftp://SomeFileLocation");
scheduler.ScheduleJob(job, Triggers.TimeTrigger());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment