Created
July 18, 2015 14:47
-
-
Save punitganshani/36d451a5585a589e703b to your computer and use it in GitHub Desktop.
Scheduling Background Tasks in ASP.NET using Quartz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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