Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Hive/3.3/HiveJanitor.cs @ 14385

Last change on this file since 14385 was 9215, checked in by fschoepp, 12 years ago

#1888:

  • Janitor is now working as expected in Windows Azure
  • Added basic support for experiments (draggable experiments)
  • Added methods to save/read experiments from TableStorage
  • The job status can now be retrieved by using the GetTasks/GetTaskData methods
  • Added a class to convert JSON-objects to Algorithm instances
  • Web page: Added experiment button to navigation
File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Threading;
24using HeuristicLab.Services.Hive.DataAccess;
25using System.Diagnostics;
26
27namespace HeuristicLab.Services.Hive {
28  public class HiveJanitor {
29    private bool stop;
30    private AutoResetEvent waitHandle;
31
32    private DataAccess.ITransactionManager trans {
33      get { return ServiceLocator.Instance.TransactionManager; }
34    }
35
36    private IEventManager eventManager {
37      get { return ServiceLocator.Instance.EventManager; }
38    }
39
40    private IHiveDao dao {
41      get { return ServiceLocator.Instance.HiveDao; }
42    }
43
44    public HiveJanitor() {
45      stop = false;
46      waitHandle = new AutoResetEvent(true);
47    }
48
49    public void StopJanitor() {
50      stop = true;
51      waitHandle.Set();
52    }
53
54    public void Run() {
55      while (!stop) {
56        try {
57          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: starting cleanup");
58          Trace.WriteLine("HiveJanitor: starting cleanup");
59          bool cleanup = false;
60          DateTime lastCleanup = DateTime.MinValue;
61          trans.UseTransaction(() => {
62            lastCleanup = dao.GetLastCleanup();
63          }, true);
64          if (DateTime.Now - lastCleanup > HeuristicLab.Services.Hive.Properties.Settings.Default.CleanupInterval) {
65            trans.UseTransaction(() => { dao.SetLastCleanup(DateTime.Now); }, true);
66            dao.SetLastCleanup(DateTime.Now);
67            cleanup = true;
68          }
69
70          if (cleanup) {
71            eventManager.Cleanup();
72          }
73          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: cleanup finished");
74          Trace.WriteLine("HiveJanitor: cleanup finished");
75        }
76        catch (Exception e) {
77          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log(string.Format("HiveJanitor: The following exception occured: {0}", e.ToString()));
78          Trace.WriteLine(string.Format("HiveJanitor: The following exception occured: {0}", e.ToString()));
79        }
80        waitHandle.WaitOne(HeuristicLab.Services.Hive.Properties.Settings.Default.CleanupInterval);
81      }
82      waitHandle.Close();
83    }
84  }
85}
86
87
88
Note: See TracBrowser for help on using the repository browser.