|
Lines 215-222
namespace Beagle.Util {
Link Here
|
| 215 |
|
215 |
|
| 216 |
public void Cancel () |
216 |
public void Cancel () |
| 217 |
{ |
217 |
{ |
| 218 |
if (! cancelled) |
218 |
if (! cancelled) { |
| 219 |
DecrementAllTaskGroups (); |
219 |
DecrementAllTaskGroups (); |
|
|
220 |
Cleanup (); // clean up after cancelled tasks |
| 221 |
} |
| 220 |
cancelled = true; |
222 |
cancelled = true; |
| 221 |
} |
223 |
} |
| 222 |
|
224 |
|
|
Lines 284-290
namespace Beagle.Util {
Link Here
|
| 284 |
|
286 |
|
| 285 |
/////////////////////////////// |
287 |
/////////////////////////////// |
| 286 |
|
288 |
|
|
|
289 |
// Clean-up is called whenever we know that a task will never |
| 290 |
// be executed. It is never called on tasks for who DoTaskReal |
| 291 |
// has been called (except when rescheduled). Cleanup is also |
| 292 |
// called when a task is cancelled. |
| 293 |
|
| 294 |
public void Cleanup () |
| 295 |
{ |
| 296 |
try { |
| 297 |
DoCleanup (); |
| 298 |
} catch (Exception ex) { |
| 299 |
Logger.Log.Warn ("Caught exception cleaning up task '{0}'", Tag); |
| 300 |
Logger.Log.Warn (ex); |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
protected virtual void DoCleanup () |
| 305 |
{ |
| 306 |
// Do nothing by default |
| 307 |
} |
| 308 |
|
| 309 |
/////////////////////////////// |
| 310 |
|
| 287 |
// Sort from lowest to highest priority |
311 |
// Sort from lowest to highest priority |
|
|
312 |
// FIXME: This does not define a total ordering |
| 313 |
// on the set of all tasks, so use it with care. |
| 288 |
public int CompareTo (object obj) |
314 |
public int CompareTo (object obj) |
| 289 |
{ |
315 |
{ |
| 290 |
Task other = obj as Task; |
316 |
Task other = obj as Task; |
|
Lines 746-751
namespace Beagle.Util {
Link Here
|
| 746 |
Hook pre_hook = null; |
772 |
Hook pre_hook = null; |
| 747 |
Hook post_hook = null; |
773 |
Hook post_hook = null; |
| 748 |
ArrayList to_be_executed = new ArrayList (); |
774 |
ArrayList to_be_executed = new ArrayList (); |
|
|
775 |
Hashtable max_priority_by_source = new Hashtable (); |
| 749 |
|
776 |
|
| 750 |
while (running) { |
777 |
while (running) { |
| 751 |
|
778 |
|
|
Lines 766-780
namespace Beagle.Util {
Link Here
|
| 766 |
// the next one to execute. |
793 |
// the next one to execute. |
| 767 |
DateTime now = DateTime.Now; |
794 |
DateTime now = DateTime.Now; |
| 768 |
DateTime next_trigger_time = DateTime.MaxValue; |
795 |
DateTime next_trigger_time = DateTime.MaxValue; |
|
|
796 |
|
| 797 |
// Make a first pass over our tasks, finding the |
| 798 |
// highest-priority item per source. |
| 799 |
max_priority_by_source.Clear (); |
| 800 |
foreach (Task task in tasks_by_tag.Values) { |
| 801 |
if (task.Blocked || task.TriggerTime >= now) |
| 802 |
continue; |
| 803 |
if (max_priority_by_source.Contains (task.Source)) { |
| 804 |
Priority p = (Priority) max_priority_by_source [task.Source]; |
| 805 |
if (p < task.Priority) |
| 806 |
max_priority_by_source [task.Source] = task.Priority; |
| 807 |
} else { |
| 808 |
max_priority_by_source [task.Source] = task.Priority; |
| 809 |
} |
| 810 |
} |
| 811 |
|
| 812 |
// Now make a second pass over the tasks and find |
| 813 |
// the highest-priority item. We use the information |
| 814 |
// from the first pass to correctly prioritize maintenance tasks. |
| 769 |
Task next_task = null; |
815 |
Task next_task = null; |
| 770 |
foreach (Task task in tasks_by_tag.Values) { |
816 |
foreach (Task task in tasks_by_tag.Values) { |
| 771 |
if (task.Blocked) |
817 |
if (task.Blocked) |
| 772 |
continue; |
818 |
continue; |
|
|
819 |
if (task.TriggerTime >= now) { |
| 820 |
if (task.TriggerTime < next_trigger_time) |
| 821 |
next_trigger_time = task.TriggerTime; |
| 822 |
continue; |
| 823 |
} |
| 824 |
|
| 825 |
// If this is a maintenance task and there is a high-priority |
| 826 |
// task from the same source, skip it. |
| 827 |
if (task.Priority == Priority.Maintenance) { |
| 828 |
Priority p = (Priority) max_priority_by_source [task.Source]; |
| 829 |
if (p > task.Priority) |
| 830 |
continue; |
| 831 |
} |
| 832 |
|
| 773 |
if (task.TriggerTime < now) { |
833 |
if (task.TriggerTime < now) { |
| 774 |
if (next_task == null || next_task.CompareTo (task) < 0) |
834 |
if (next_task == null || next_task.CompareTo (task) < 0) |
| 775 |
next_task = task; |
835 |
next_task = task; |
| 776 |
} else if (task.TriggerTime < next_trigger_time) |
836 |
} |
| 777 |
next_trigger_time = task.TriggerTime; |
|
|
| 778 |
} |
837 |
} |
| 779 |
|
838 |
|
| 780 |
// If we didn't find a task, wait for the next trigger-time |
839 |
// If we didn't find a task, wait for the next trigger-time |
|
Lines 910-915
namespace Beagle.Util {
Link Here
|
| 910 |
foreach (Task task in shutdown_task_queue) |
969 |
foreach (Task task in shutdown_task_queue) |
| 911 |
if (! task.Cancelled && ! task.Blocked) |
970 |
if (! task.Cancelled && ! task.Blocked) |
| 912 |
task.DoTask (); |
971 |
task.DoTask (); |
|
|
972 |
|
| 973 |
// Call Cleanup on all of our unexecuted tasks |
| 974 |
foreach (Task task in tasks_by_tag.Values) |
| 975 |
task.Cleanup (); |
| 913 |
|
976 |
|
| 914 |
if (Debug) |
977 |
if (Debug) |
| 915 |
Logger.Log.Debug ("Scheduler.Worker finished"); |
978 |
Logger.Log.Debug ("Scheduler.Worker finished"); |