}// ----------------------------------------- //-- Internal task status handler private void _onTaskStatus(CTaskStatus s,CTask t) { // Pass this through onTaskStatus(s,t); switch (s) { case CTaskStatus.complete: LOG.log("[CJOB] : Task Completed: {0} ",t); taskData = t.dataSend; TASKS_COMPLETE++; TASKS_COMPLETION_PERCENT = (int)Math.Ceiling((100.0f / TASKS_TOTAL) * TASKS_COMPLETE); TASK_LAST = t; onJobStatus(CJobStatus.taskEnd,this); killTask(t); feedQueue(); break; case CTaskStatus.fail: // Fail the whole job // FUTURE, make non-important tasks where the job won't fail? LOG.log("[CJOB] : Error : Task Failed: {0}",t); killTask(t); fail(t.ERROR[0],t.ERROR[1]); break; case CTaskStatus.start: TASK_LAST = t; onJobStatus(CJobStatus.taskStart,this); break; } }// -----------------------------------------
}// ----------------------------------------- // End a task properly // Task has either Completed or Failed private void killTask(CTask t) { TASKS_RUNNING--; slots_active[t.SLOT] = false; slots_progress[t.SLOT] = -1; if (!t.FLAG_PROGRESS_DISABLE) { TASKS_COMPLETED_PROGRESS += TASK_PROGRESS_RATIO * 100; } currentTasks.Remove(t); t.kill(); }// -----------------------------------------
}// ----------------------------------------- //-- Internal task status handler private void _onTaskStatus(CTaskStatus s,CTask t) { // Pass this through onTaskStatus(s,t); switch (s) { case CTaskStatus.complete: LOG.log("[CJOB]: Task Completed: {0} ",t); taskData = t.dataSend; TASKS_COMPLETE++; TASK_LAST = t; onJobStatus(CJobStatus.taskEnd,this); killTask(t); feedQueue(); break; // TODO: I could report the progress on a timer // This is not ideal if there are many tasks running at once (CPU wise) // NOTE: Will not get called from FLAG_NO_PROGRESS tasks case CTaskStatus.progress: slots_progress[t.SLOT] = t.PROGRESS; // LOG.log("Task:{0}, slot:{2} progress:{1}",t.name,t.PROGRESS,t.SLOT); calculateProgress(); onJobStatus(CJobStatus.progress,this); break; case CTaskStatus.fail: // Fail the whole job LOG.log("[CJOB]: Error : Task Failed: {0}",t); killTask(t); fail(t.ERROR[0],t.ERROR[1]); break; case CTaskStatus.start: TASK_LAST = t; onJobStatus(CJobStatus.taskStart,this); break; } }// -----------------------------------------
}// ----------------------------------------- // Add a task to the top of the queue public CJob addNextAsync(CTask t) { t.async = true; addNext(t); return(this); }// -----------------------------------------
}// ----------------------------------------- // Add a task to the top of the queue public CJob addNext(CTask t) { taskQueue.Insert(0, t); TASKS_TOTAL++; return(this); }// -----------------------------------------
}// ----------------------------------------- // Add a task public CJob add(CTask t) { taskQueue.Add(t); TASKS_TOTAL++; return(this); }// -----------------------------------------
}// ----------------------------------------- // End a task properly // Task has either Completed or Failed private void killTask(CTask t) { slots[t.SLOT] = false; currentTasks.Remove(t); t.kill(); }// -----------------------------------------