Created
July 17, 2012 22:56
-
-
Save ferventcoder/3132704 to your computer and use it in GitHub Desktop.
WebBackgrounder - IoC improvements
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
Bind<IJob>().ToMethod(context => new SyncWithMeetingsJob(context.Kernel, interval: TimeSpan.FromMinutes(Config.GetConfigurationSettings().MeetingsMinutesBetweenUpdates), timeout: TimeSpan.FromMinutes(20))).InSingletonScope(); |
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
public class SyncWithMeetingsJob : Job | |
{ | |
private readonly IKernel _kernel; | |
public SyncWithMeetingsJob(IKernel kernel, TimeSpan interval, TimeSpan timeout) | |
: base("Sync With Meetings", interval, timeout) | |
{ | |
_kernel = kernel; | |
} | |
public override Task Execute() | |
{ | |
var meetingService = _kernel.Get<IMeetingService>(); | |
return new Task(meetingService.UpdateMeetings); | |
} | |
} |
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
public static class BackgroundJobManager | |
{ | |
private static JobManager _jobManager; | |
public static void Start() | |
{ | |
"BackgroundJobManager".Log().Debug(()=>"BackgroundJobManager is registering and starting jobs"); | |
var container = NinjectContainer.Kernel; | |
var jobs = container.GetAll<IJob>(); | |
var jobCoordinator = new SingleServerJobCoordinator(); | |
_jobManager = new JobManager(jobs, jobCoordinator); | |
_jobManager.Fail(e => | |
{ | |
ErrorLog.GetDefault(null).Log(new Error(e)); | |
"BackgroundJobManager".Log().Error("Job Manager is having issues: {0}{1}".FormatWith(System.Environment.NewLine,e.ToString())); | |
}); | |
_jobManager.Start(); | |
} | |
public static void Stop() | |
{ | |
"BackgroundJobManager".Log().Debug(()=>"BackgroundJobManager is stopping jobs"); | |
_jobManager.Dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Notice I am not explicitly making reference to the jobs in
BackgroundJobManager
. Just container.GetAll() and boom. :D