public async Task <bool> StartAsync(CancellationToken cancellationToken) { this.State = JobbrState.Initializing; this.LogVersions(); Logger.InfoFormat("The JobServer has been set-up by the following configurations"); this.configurationManager.LogConfiguration(); this.State = JobbrState.Validating; try { this.configurationManager.ValidateConfigurationAndThrowOnErrors(); Logger.Info("The configuration was validated and seems ok. Final configuration below:"); this.configurationManager.LogConfiguration(); } catch (Exception) { this.State = JobbrState.Error; throw; } this.State = JobbrState.Starting; var waitForDbTask = new Task(this.WaitForDb, cancellationToken); var startComponents = waitForDbTask.ContinueWith( t => { this.RegisterJobsFromRepository(); this.StartInternalComponents(); this.StartOptionalComponents(); this.isRunning = true; }, cancellationToken); waitForDbTask.Start(); await Task.WhenAll(waitForDbTask, startComponents); this.State = JobbrState.Running; return(true); }
public bool Start(int waitForStartupTimeout = 2000) { var startupTask = this.StartAsync(CancellationToken.None); try { startupTask.Wait(waitForStartupTimeout); } catch (AggregateException e) { this.State = JobbrState.Error; throw e.InnerExceptions[0]; } if (!startupTask.IsCompleted) { Logger.FatalFormat("Jobbr was unable to start within {0}ms. Keep starting but returning now from Start()", waitForStartupTimeout); return(false); } return(true); }