View | Details | Raw Unified | Return to bug 113626
Collapse All | Expand All

(-)Filters/FilterPdf.cs (-1 / +1 lines)
Lines 97-103 namespace Beagle.Filters { Link Here
97
			Process pc = new Process ();
97
			Process pc = new Process ();
98
			pc.StartInfo.FileName = "pdftotext";
98
			pc.StartInfo.FileName = "pdftotext";
99
			// FIXME: We probably need to quote special chars in the path
99
			// FIXME: We probably need to quote special chars in the path
100
			pc.StartInfo.Arguments = String.Format ("-nopgbrk -enc UTF-8 \"{0}\" -", FileInfo.FullName);
100
			pc.StartInfo.Arguments = String.Format ("-q -nopgbrk -enc UTF-8 \"{0}\" -", FileInfo.FullName);
101
			pc.StartInfo.RedirectStandardInput = false;
101
			pc.StartInfo.RedirectStandardInput = false;
102
			pc.StartInfo.RedirectStandardOutput = true;
102
			pc.StartInfo.RedirectStandardOutput = true;
103
			pc.StartInfo.UseShellExecute = false;
103
			pc.StartInfo.UseShellExecute = false;
(-)Util/Scheduler.cs (-3 / +66 lines)
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");
(-)beagled/LuceneQueryable.cs (-1 / +28 lines)
Lines 110-115 namespace Beagle.Daemon { Link Here
110
110
111
			// Schedule an optimize, just in case
111
			// Schedule an optimize, just in case
112
			ScheduleOptimize ();
112
			ScheduleOptimize ();
113
114
			Shutdown.ShutdownEvent += new Shutdown.ShutdownHandler (OnShutdownEvent);
113
		}
115
		}
114
116
115
		protected string IndexName {
117
		protected string IndexName {
Lines 141-146 namespace Beagle.Daemon { Link Here
141
143
142
		/////////////////////////////////////////
144
		/////////////////////////////////////////
143
145
146
		virtual protected void ShutdownHook ()
147
		{
148
149
		}
150
151
		private void OnShutdownEvent ()
152
		{
153
			lock (request_lock) 
154
				pending_request.Cleanup ();
155
156
			try {
157
				ShutdownHook ();
158
			} catch (Exception ex) {
159
				Logger.Log.Warn ("Caught exception in shutdown hook");
160
				Logger.Log.Warn (ex);
161
			}
162
		}
163
164
		/////////////////////////////////////////
165
144
		virtual public bool AcceptQuery (Query query)
166
		virtual public bool AcceptQuery (Query query)
145
		{
167
		{
146
			// Don't accept queries on empty indexes.
168
			// Don't accept queries on empty indexes.
Lines 422-427 namespace Beagle.Daemon { Link Here
422
						queryable.ConditionalFlush ();
444
						queryable.ConditionalFlush ();
423
				}
445
				}
424
			}
446
			}
447
448
			override protected void DoCleanup ()
449
			{
450
				indexable.Cleanup ();
451
			}
425
		}
452
		}
426
453
427
		public Scheduler.Task NewAddTask (Indexable indexable)
454
		public Scheduler.Task NewAddTask (Indexable indexable)
Lines 758-764 namespace Beagle.Daemon { Link Here
758
						}
785
						}
759
786
760
						if (please_add_a_new_task) {
787
						if (please_add_a_new_task) {
761
							Logger.Log.Debug ("Adding child {0}", child.Uri);
788
							//Logger.Log.Debug ("Adding child {0}", child.Uri);
762
							Scheduler.Task task = NewAddTask (child);
789
							Scheduler.Task task = NewAddTask (child);
763
							ThisScheduler.Add (task);
790
							ThisScheduler.Add (task);
764
						}
791
						}
(-)BeagleClient/Indexable.cs (-2 / +2 lines)
Lines 269-275 namespace Beagle { Link Here
269
		{
269
		{
270
			if (DeleteContent) {
270
			if (DeleteContent) {
271
				if (contentUri != null) {
271
				if (contentUri != null) {
272
					Logger.Log.Debug ("Cleaning up {0}", contentUri.LocalPath);
272
					//Logger.Log.Debug ("Cleaning up {0}", contentUri.LocalPath);
273
					try {
273
					try {
274
						File.Delete (contentUri.LocalPath);
274
						File.Delete (contentUri.LocalPath);
275
					} catch (Exception ex)
275
					} catch (Exception ex)
Lines 279-285 namespace Beagle { Link Here
279
					contentUri = null;
279
					contentUri = null;
280
				}
280
				}
281
				if (hotContentUri != null) {
281
				if (hotContentUri != null) {
282
					Logger.Log.Debug ("Cleaning up {0}", hotContentUri.LocalPath);
282
					//Logger.Log.Debug ("Cleaning up {0}", hotContentUri.LocalPath);
283
					try {
283
					try {
284
						File.Delete (hotContentUri.LocalPath);
284
						File.Delete (hotContentUri.LocalPath);
285
					} catch (Exception ex)
285
					} catch (Exception ex)
(-)beagled/IndexerRequest.cs (+10 lines)
Lines 119-123 namespace Beagle.Daemon { Link Here
119
		public bool IsEmpty {
119
		public bool IsEmpty {
120
			get { return Count == 0 && ! OptimizeIndex; }
120
			get { return Count == 0 && ! OptimizeIndex; }
121
		}
121
		}
122
123
		public void Cleanup ()
124
		{
125
			if (indexables_by_uri != null)
126
				foreach (Indexable i in indexables_by_uri.Values)
127
					i.Cleanup ();
128
			else
129
				foreach (Indexable i in indexables)
130
					i.Cleanup ();
131
		}
122
	}
132
	}
123
}
133
}
(-)beagled/RemoteIndexer.cs (+1 lines)
Lines 90-95 namespace Beagle.Daemon { Link Here
90
90
91
			if (response == null) {
91
			if (response == null) {
92
				Logger.Log.Error ("Something terrible happened --- Flush failed");
92
				Logger.Log.Error ("Something terrible happened --- Flush failed");
93
				request.Cleanup ();
93
				return null;
94
				return null;
94
			}
95
			}
95
			
96
			

Return to bug 113626