private void Init() { using (var db = new AryaServicesDbDataContext()) { //Restart tasks that were "working" in the previous run (if any) var workingTasks = db.AryaTasks.Where(t => t.Status == WorkerState.Working.ToString()); workingTasks.ForEach(t => t.Status = WorkerState.New.ToString()); db.SubmitChanges(); } }
protected void CancelCurrentJob(object sender, CommandEventArgs e) { var taskId = Guid.Parse(e.CommandArgument.ToString()); using (var taskDc = new AryaServicesDbDataContext()) { var task = taskDc.AryaTasks.First(t => t.ID == taskId); if (task.Status == WorkerState.New.ToString()) { task.Status = WorkerState.AbortedByUser.ToString(); taskDc.SubmitChanges(); } else { lblMessage.Text = "Could not cancel Job - it had already started before cancel request was sent to server."; } BindGridView(); } }
public void SubmitJobs() { // get data context using (var db = new AryaServicesDbDataContext()) { // get a list of jobs to be executed var now = DateTime.Now; var jobs = db.AryaSchedules.Where(s => (s.NextExecution == null || s.NextExecution <= now)); // add each job to the task queue foreach (var job in jobs) { string newArgumentDirectoryPath = Path.Combine(job.ProjectID.ToString(), Guid.NewGuid().ToString()); DirectoryCopy(Path.Combine(Settings.Default.ArgumentFileBasePath, job.ArgumentDirectoryPath), Path.Combine(Settings.Default.ArgumentFileBasePath, newArgumentDirectoryPath), true); //File.Copy(); var newJob = new AryaTask { ID = Guid.NewGuid(), ScheduleID = job.ID, Description = job.Description, ArgumentDirectoryPath = newArgumentDirectoryPath, Status = "New", SubmittedBy = job.SubmittedBy, SubmittedOn = now, ProjectID = job.ProjectID, LastUpdateOn = now, JobType = job.JobType }; db.AryaTasks.InsertOnSubmit(newJob); Logger.GetLogWriter().Info("SchedueJobId:" + job.ID + "was submitted as regular job"); // update the date of execution of the selected job job.NextExecution = now.AddMinutes(job.Interval); job.LastExecution = now; // update the database db.SubmitChanges(); } } }
public async Task ProcessJobs(object processBucket) { //CurrentLogWriter.Debug("Job assigner has started processing jobs."); try { AryaTask job; using (var aryaServicesDb = new AryaServicesDbDataContext()) { job = aryaServicesDb.AryaTasks.FirstOrDefault( s => s.Status.ToLower() == WorkerState.New.ToString().ToLower()); if (job == null) { return; } CurrentLogWriter.InfoFormat( "Job ID: {0} Starting\tDescription:{1}\tSubmitted by:{2}\tSubmitted on:{3}\tJob type:{4}\tProcess bucket:{5}", job.ID, job.Description, job.SubmittedBy, job.SubmittedOn, job.JobType, processBucket); job.JobAssignedOn = DateTime.Now; job.Status = WorkerState.Working.ToString(); aryaServicesDb.SubmitChanges(); } string currentJobStatus, emailAddresses = string.Empty; try { if (JobProcessors.ContainsKey(job.JobType)) { //create the job instance var currentJobType = JobProcessors[job.JobType]; var jobExecutor = (WorkerBase) Activator.CreateInstance(currentJobType, new object[] { Path.Combine(Settings.Default.ArgumentFileBasePath, job.ArgumentDirectoryPath) }); jobExecutor.CurrentLogWriter = CurrentLogWriter; jobExecutor.WorkerStatusChange += AryaServices.UpdateWorkerStatusInDb; emailAddresses = jobExecutor.Arguments.NotificationEmailAddresses; ProcessEmailJobStatus(emailAddresses, job, true, "Started"); await Task.Run(() => jobExecutor.Run()); jobExecutor.SaveSummary(); currentJobStatus = jobExecutor.Summary.State.ToString(); } else { currentJobStatus = WorkerState.Abort.ToString(); CurrentLogWriter.ErrorFormat("{0}: {1} not found in the dll provided", job.ID, job.JobType); } } catch (Exception ex) { var message = string.Empty; var e = ex; while (e != null) { message = Environment.NewLine + e.Message; e = e.InnerException; } CurrentLogWriter.Error(ex.Source + message + Environment.NewLine + ex.StackTrace); currentJobStatus = WorkerState.Abort.ToString(); CurrentLogWriter.Error(ex.SerializeObject()); } using (var aryaServicesDb = new AryaServicesDbDataContext()) { job = aryaServicesDb.AryaTasks.First(t => t.ID == job.ID); job.Status = currentJobStatus; ProcessEmailJobStatus(emailAddresses, job, true); CurrentLogWriter.InfoFormat("Job Id: {0} Finished processing, Last Status: {1}", job.ID, currentJobStatus); job.LastUpdateOn = DateTime.Now; aryaServicesDb.SubmitChanges(); } } catch (Exception ex) { CurrentLogWriter.Error(ex.SerializeObject()); } CurrentLogWriter.Debug("Job assigner is exiting."); }