public void Update(JobDto dto) { try { if (jobs.TryGetValue(dto.Id, out var job)) { job.State = dto.State; job.ExecutedDate = DateTime.Now; JobUpdated?.Invoke(job); logger.LogDebug($"{job}"); if (job.State != JobState.Finished && job.State != JobState.Error) { return; } JobFinished?.Invoke(job); Clean(); } else { logger.LogWarning($"Can't find job with Id: {dto.Id}"); } } catch (Exception exception) { logger.LogError($"Update error: {dto}, {exception.Message}"); } }
/// <summary> /// Stops monitoring the job and fires up <see cref="E:Sitecore.Jobs.AsyncUI.JobMonitor.JobFinished" /> event. /// </summary> private void OnJobFinished(RunnerOutput runnerOutput) { JobHandle = Handle.Null; var eventArgs = new SessionCompleteEventArgs { RunnerOutput = runnerOutput }; JobFinished?.Invoke(this, eventArgs); }
public void StartJob(Agent agent) { _agent = agent; Debug.LogError("Amele job Start"); _agent.SetDestination(_target, () => { _reachedTarget = true; Debug.Log("Geldim AMK."); JobFinished?.Invoke(); }); }
public void DoJob() { try { OnDoJob(); JobFinished?.Invoke(this, EventArgs.Empty); } catch (Exception err) { JobFailed?.Invoke(this, err); throw; } }
private void NextJob_Finished(object sender, ShareJobFinishedEventArgs e) { IShareJob job = (IShareJob)sender; if (e.ErrorMessage != null) { JobFinished?.Invoke(this, new ShareJobQueueStatusEventArgs(job, "Failed: " + e.ErrorMessage, true)); } else { JobFinished?.Invoke(this, new ShareJobQueueStatusEventArgs(job, "Finished")); } }
/// <summary> /// Does the actual conversion process of the job /// </summary> private void DoConversion(Job job, string targetFilename) { DisableIrrelevantProfileSettings(job.Profile); try { if (job.JobInfo.SourceFiles.Count == 0) { Logger.Info("COM: JobInfo has no source files and will be skipped"); return; } Logger.Trace("COM: Creating workflow"); var errorNotifier = new ErrorNotifierCom(); var workflow = _workflowFactory.BuildWorkflow(targetFilename, errorNotifier); Logger.Trace("COM: Running workflow"); var workflowResult = workflow.RunWorkflow(job); if (workflowResult == WorkflowResult.Error) { var errorCode = errorNotifier.Error[0]; throw new COMException(_errorCodeInterpreter.GetErrorText(errorCode, true)); } if (workflowResult == WorkflowResult.AbortedByUser) { Logger.Info("COM: The job '{0}' was aborted by the user.", job.JobInfo.Metadata.Title); } if (workflowResult == WorkflowResult.Finished) { IsSuccessful = true; } } catch (Exception e) { throw new COMException(e.Message); } finally { Logger.Trace("COM: Removing jobinfo from the queue."); _jobInfoQueue.Remove(job.JobInfo, true); IsFinished = true; JobFinished?.Invoke(this, EventArgs.Empty); } }
public Task Execute(IJobExecutionContext context) { return(Task.Run(() => { JobStarting?.Invoke(this, new EventArgs()); TFGetLatestVersion(); BuildAll(); RebuildDataModels(); PushMessageQueue(this.GetType().ToString()); JobFinished?.Invoke(this, new EventArgs()); })); }
public void JobUpdate() { if (_reachedDestination) { _currentTargetFlammable.Extinguish(_agent.ExtinguishRate); if (_currentTargetFlammable.Extinguished) { JobFinished?.Invoke(_currentTargetFlammable); if (!AssignNewFlammable()) { Debug.Log("No flammables remain in the area."); } } } }
/// <summary> /// Executes the job. /// </summary> /// <param name="job">The job.</param> /// <exception cref="NotImplementedException"></exception> public void ExecuteJob(IEngineJob job) { // Check if task can be executed if (!job.CanBeExecuted()) { job.AddMessage($"The job cannot be executed.", MessageSeverity.Error); throw new EngineException(logger, $"The job cannot be executed. This job was aborted."); } // Execute job if (JobStarted != null) { JobStarted.Invoke((Guid)job.EntityId, (Guid)job.InstanceID); } job.Start(); // Stop the job job.Stop(); if (job.HasErrors) { if (JobFinished != null) { JobFinished.Invoke((Guid)job.EntityId, (Guid)job.InstanceID, false); } job.AddMessage($"The job (instance: {job.InstanceID}) was not executed cause one or more errors occurs.", MessageSeverity.Error); throw new EngineException(logger, $"The job (instance: {job.InstanceID}) was not executed cause one or more errors occurs. This job was aborted."); } else if (job.HasWarnings) { if (JobFinished != null) { JobFinished.Invoke((Guid)job.EntityId, (Guid)job.InstanceID, false); } job.AddMessage($"The job (instance: {job.InstanceID}) was executed but one or more warning occurs.", MessageSeverity.Warning); throw new EngineException(logger, $"The job (instance: {job.InstanceID}) was executed but one or more warning occurs. This job was aborted."); } if (JobFinished != null) { JobFinished.Invoke((Guid)job.EntityId, (Guid)job.InstanceID, true); } }
private void _updateTimer_Elapsed(object sender) { var scsTelemetry = SharedMemory.Update <SCSTelemetry>(); var time = scsTelemetry.Timestamp; Data?.Invoke(scsTelemetry, time != lastTime); // Job close & start events if (wasFinishingJob != scsTelemetry.SpecialEventsValues.JobFinished) { wasFinishingJob = scsTelemetry.SpecialEventsValues.JobFinished; if (scsTelemetry.SpecialEventsValues.JobFinished) { JobFinished?.Invoke(this, new EventArgs()); } } if (wasOnJob != scsTelemetry.SpecialEventsValues.OnJob) { wasOnJob = scsTelemetry.SpecialEventsValues.OnJob; if (scsTelemetry.SpecialEventsValues.OnJob) { JobStarted?.Invoke(this, new EventArgs()); } } if (wasConnected != scsTelemetry.SpecialEventsValues.TrailerConnected) { wasConnected = scsTelemetry.SpecialEventsValues.TrailerConnected; if (scsTelemetry.SpecialEventsValues.TrailerConnected) { TrailerConnected?.Invoke(this, new EventArgs()); } else { TrailerDisconnected?.Invoke(this, new EventArgs()); } } lastTime = time; }
private async Task <DownloadResult> FinishJob(Exception exception = null) { CanPause = false; if (exception is OperationCanceledException) { Status = DownloadJobStatus.Canceled; } else if (exception != null) { Exception = exception; Status = DownloadJobStatus.Faulted; } else { Status = DownloadJobStatus.Finished; } DownloadResult = _downloadResult; List <Task> invokedCallbacks = new List <Task>(); foreach (DownloadFinishedCallback callback in downloadFinishedCallbacks) { invokedCallbacks.Add(callback.Invoke(this)); } if (invokedCallbacks.Count > 0) { try { await Task.Run(() => Task.WhenAll(invokedCallbacks), _runCancellationToken).ConfigureAwait(false); } catch (Exception ex) { Logger.log?.Error($"Error in {this.GetType().Name} download finished callback: {ex.Message}"); Logger.log?.Debug(ex); } } JobFinished?.Invoke(this, new DownloadJobFinishedEventArgs(SongHash, _downloadResult?.Status ?? DownloadResultStatus.Unknown, DownloadResult.DownloadContainer)); return(DownloadResult); }
private static void Job_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (sender is DownloadJob job && e.PropertyName.Equals(nameof(job.Status))) { System.Diagnostics.Debug.WriteLine("下载任务状态改变:" + "[" + job.Status + "]" + job.Title); switch (job.Status) { case DownloadJobStatus.Created: // 是不会被用到的case waitingJobs.Add(job); // 添加任务到等待列表 break; case DownloadJobStatus.Ready: // Job就绪 等待运行 waitingJobs.RemoveJob(job); // 从等待列表移除 downloadJobs.Enqueue(job); // 任务排队 break; case DownloadJobStatus.Running: // 开始下载 lock (downloadingJobs) downloadingJobs.Add(job); // 任务开始 break; case DownloadJobStatus.Pause: // 下载暂停 lock (downloadingJobs) downloadingJobs.RemoveJob(job); // 从正在下载列表中移除 waitingJobs.Add(job); // 添加任务到暂停列表 job.DownloadResume += job_resume; // 等待继续 break; case DownloadJobStatus.Cancel: // 下载取消 case DownloadJobStatus.Failed: // 下载失败 case DownloadJobStatus.Finished: // 下载完成 lock (downloadingJobs) downloadingJobs.RemoveJob(job); // 从正在下载列表中移除 //AutoRemove(downloadingJobs);// 自动从列表中移除已完成任务 job.PropertyChanged -= Job_PropertyChanged; // 取消订阅 JobFinished?.Invoke(job); break; default: break; } } }
public async Task RunArea(int x1, int y1, int x2, int y2, Municipality m) { cancellationSource = new CancellationTokenSource(); jobs = new ObservableCollection <Job>(); Dictionary <TileId, Tile> tiles = new Dictionary <TileId, Tile>(); for (int x = x1; x <= x2; x++) { for (int y = y1; y <= y2; y++) { TileId id = new TileId(x, y); if (repository.Municipalities.map[id] != m.Id) { continue; } if (repository.Tiles.ContainsKey(id)) { tiles[id] = repository.Tiles[id]; } else { var tile = repository.GenerateTile(id); tiles[id] = repository.Tiles[id] = tile; } repository.UpdateTile(tiles[id]); } } waitingQueue = new BufferBlock <Tile>(new DataflowBlockOptions() { EnsureOrdered = true }); workerBlock = new TransformBlock <Tile, Tile>(async t => { t.Rescan(repository.DirectoryForTile(t.Id)); var job = Job.NextJob(t); if (job == null) { return(t); } JobStarted.Invoke(this, job); await job.Run(cancellationSource.Token, Cleanup); t.Rescan(repository.DirectoryForTile(t.Id)); JobFinished.Invoke(this, job); byte[] csvLine = job.CsvBytes; repository.logFile.Write(csvLine, 0, csvLine.Length); repository.logFile.Flush(); return(t); }, new ExecutionDataflowBlockOptions() { CancellationToken = cancellationSource.Token, MaxDegreeOfParallelism = workers, }); //ActionBlock<Tile> mapUpdater = new ActionBlock<Tile>(t => repository.UpdateTile(t)); TaskCompletionSource <int> finishTask = new TaskCompletionSource <int>(); int finishedCounter = tiles.Count; ActionBlock <Tile> tileFinished = new ActionBlock <Tile>(t => { finishedCounter--; if (finishedCounter == 0) { finishTask.SetResult(finishedCounter); } }); waitingQueue.LinkTo(workerBlock); link = workerBlock.LinkTo(waitingQueue, t => Job.NextJob(t) != null); workerBlock.LinkTo(tileFinished, t => Job.NextJob(t) == null); //workerBlock.LinkTo(mapUpdater); foreach (var pair in tiles) { await waitingQueue.SendAsync(pair.Value); } await finishTask.Task; }
protected virtual void OnJobFinished(CustomEventArgs e) { JobFinished?.Invoke(this, e); }
protected void OnJobFinished() { JobFinished?.Invoke(this, new WorkStateEventArgs(CurrentWorkState)); }
private void Timer_Tick(object sender, EventArgs e) { if (MainWindow.Paused) { return; } if (JobQueue.Count == 0 && PriorityJobQueue.Count == 0) { return; } var job = (PriorityJobQueue.Count > 0) ? PriorityJobQueue.Dequeue() : JobQueue.Dequeue(); UIContext.Send((a) => { try { switch (job.Item2) { case Action.Add: collection.Add(job.Item1); break; case Action.Remove: if (equilityComparer == null) { collection.Remove(job.Item1); } else { T toRemove = default(T); foreach (T item in collection) { if (equilityComparer(job.Item1, item)) { toRemove = item; break; } } collection.Remove(toRemove); } break; } } catch (Exception ex) { // ignore for now } }, null); if (JobQueue.Count + PriorityJobQueue.Count >= 500) { timer.Interval = TimeSpan.FromMilliseconds(30); } else { timer.Interval = TimeSpan.FromMilliseconds(60); } JobFinished?.Invoke(this, job, collection); }
protected void OnJobFinished(WorkState state) { JobFinished?.Invoke(this, new WorkStateEventArgs(state)); }
private void OnJobFinished(EventArgs e) { JobFinished?.Invoke(this, e); }
static void OnJobFinished(IJob job) { JobFinished?.Invoke(job); }
private void Job_Finished(object sender, ShareJobFinishedEventArgs e) { // TODO: make this pass the IShareJob as well JobFinished?.Invoke(this, e); }
protected void OnJobFinished(EventArgs e) { JobFinished?.Invoke(this, e); }
private static void OnJobFinished(AsyncJob args) { JobFinished?.Invoke(JobFinished, args); }