Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Tools/HeuristicLab.HiveDrain/HeuristicLab.HiveDrain/JobDownloader.cs @ 9694

Last change on this file since 9694 was 9694, checked in by ascheibe, 11 years ago

#2017 added a HL application based on apetrei's Hive Drain to the tools branch

File size: 1.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Threading;
5using HeuristicLab.Clients.Hive;
6using HeuristicLab.Core;
7
8
9namespace HiveDrain {
10  /// <summary>
11  /// Retrieves all jobs and starts downloading their tasks
12  /// </summary>
13  class JobDownloader {
14    public string RootLocation { get; set; }
15
16    public string NamePattern { get; set; }
17
18    private ILog log;
19
20    public JobDownloader(string location, string pattern, ILog log) {
21      RootLocation = location;
22      NamePattern = pattern;
23      this.log = log;
24    }
25
26    public void Start() {
27      var jobsLoaded = HiveServiceLocator.Instance.CallHiveService<IEnumerable<Job>>(s => s.GetJobs());
28      Semaphore limitSemaphore = new Semaphore(HeuristicLabHiveDrainApplication.MaxParallelDownloads, HeuristicLabHiveDrainApplication.MaxParallelDownloads);
29
30      foreach (Job j in jobsLoaded) {
31        if ((!String.IsNullOrEmpty(NamePattern) && j.Name.Contains(NamePattern)) ||
32            String.IsNullOrEmpty(NamePattern)) {
33          string jobPath = Path.Combine(RootLocation, String.Format("{0} - {1}", j.Name, j.Id));
34          log.LogMessage(String.Format("\"{0}\": {1}", j.Name, j.Id));
35
36          JobTaskDownloader taskDownloader = new JobTaskDownloader(jobPath, j, limitSemaphore, log);
37          taskDownloader.Start();
38        } else {
39          log.LogMessage(String.Format("\"{0}\": {1} ---> ignored", j.Name, j.Id));
40        }
41      }
42    }
43  }
44}
Note: See TracBrowser for help on using the repository browser.