Free cookie consent management tool by TermsFeed Policy Generator

Changeset 392


Ignore:
Timestamp:
07/22/08 21:16:39 (16 years ago)
Author:
gkronber
Message:

worked on unification of agents and runs (ticket #188)

Location:
trunk/sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/AgentEntry.cs

    r390 r392  
    3737    public string Name { get; set; }
    3838    [DataMember]
     39    public DateTime CreationTime { get; set; }
     40    [DataMember]
    3941    public ProcessStatus Status { get; set; }
    4042    [DataMember]
  • trunk/sources/HeuristicLab.CEDMA.DB/Database.cs

    r390 r392  
    5555            }
    5656            using(DbCommand cmd = cnn.CreateCommand()) {
    57               cmd.CommandText = "CREATE TABLE Agent (ID integer primary key autoincrement, ProjectId integer, ParentAgentId integer, Name text, Status text default 'Unknown', ControllerAgent integer, RawData Blob)";
     57              cmd.CommandText = "CREATE TABLE Agent (ID integer primary key autoincrement, ProjectId integer, ParentAgentId integer, Name text, Status text default "+ProcessStatus.Unknown+", ControllerAgent integer, CreationTime DateTime, RawData Blob)";
    5858              cmd.Transaction = t;
    5959              cmd.ExecuteNonQuery();
     
    8383            using(DbCommand c = cnn.CreateCommand()) {
    8484              c.Transaction = t;
    85               c.CommandText = "Insert into Agent (Name, ParentAgentId, ControllerAgent, RawData) values (@Name, @ParentAgentId, @ControllerAgent, @RawData); select last_insert_rowid()";
     85              c.CommandText = "Insert into Agent (Name, ParentAgentId, ControllerAgent, CreationTime, RawData) values (@Name, @ParentAgentId, @ControllerAgent, @CreationTime, @RawData); select last_insert_rowid()";
    8686              DbParameter nameParam = c.CreateParameter();
    8787              nameParam.ParameterName = "@Name";
     
    9696              controllerParam.Value = controllerAgent;
    9797              c.Parameters.Add(controllerParam);
     98              DbParameter creationTimeParam = c.CreateParameter();
     99              creationTimeParam.ParameterName = "@CreationTime";
     100              creationTimeParam.Value = DateTime.Now;
     101              c.Parameters.Add(creationTimeParam);
    98102              DbParameter dataParam = c.CreateParameter();
    99103              dataParam.ParameterName = "@RawData";
     
    236240              DbParameter idParam = c.CreateParameter();
    237241              statusParam.ParameterName = "@Status";
    238               statusParam.Value = status;
     242              statusParam.Value = status.ToString();
    239243              idParam.ParameterName = "@Id";
    240244              idParam.Value = id;
     
    278282    }
    279283
    280     //public void UpdateRunStart(long runId, DateTime startTime) {
    281     //  rwLock.EnterWriteLock();
    282     //  try {
    283     //    using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
    284     //      cnn.Open();
    285     //      using(SQLiteTransaction t = cnn.BeginTransaction()) {
    286     //        using(SQLiteCommand c = cnn.CreateCommand()) {
    287     //          c.Transaction = t;
    288     //          c.CommandText = "Update Run set StartTime=@StartTime where id=@Id";
    289     //          DbParameter startTimeParam = c.CreateParameter();
    290     //          DbParameter idParam = c.CreateParameter();
    291     //          startTimeParam.ParameterName = "@StartTime";
    292     //          startTimeParam.Value = startTime;
    293     //          idParam.ParameterName = "@Id";
    294     //          idParam.Value = runId;
    295     //          c.Parameters.Add(startTimeParam);
    296     //          c.Parameters.Add(idParam);
    297     //          c.ExecuteNonQuery();
    298     //        }
    299     //        t.Commit();
    300     //      }
    301     //    }
    302     //  } finally {
    303     //    rwLock.ExitWriteLock();
    304     //  }
    305     //}
    306 
    307     //public void UpdateRunFinished(long runId, DateTime finishedTime) {
    308     //  rwLock.EnterWriteLock();
    309     //  try {
    310     //    using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
    311     //      cnn.Open();
    312     //      using(SQLiteTransaction t = cnn.BeginTransaction()) {
    313     //        using(SQLiteCommand c = cnn.CreateCommand()) {
    314     //          c.Transaction = t;
    315     //          c.CommandText = "Update Run set FinishedTime=@FinishedTime where id=@Id";
    316     //          DbParameter finishedTimeParam = c.CreateParameter();
    317     //          DbParameter idParam = c.CreateParameter();
    318     //          finishedTimeParam.ParameterName = "@FinishedTime";
    319     //          finishedTimeParam.Value = finishedTime;
    320     //          idParam.ParameterName = "@Id";
    321     //          idParam.Value = runId;
    322     //          c.Parameters.Add(finishedTimeParam);
    323     //          c.Parameters.Add(idParam);
    324     //          c.ExecuteNonQuery();
    325     //        }
    326     //        t.Commit();
    327     //      }
    328     //    }
    329     //  } finally {
    330     //    rwLock.ExitWriteLock();
    331     //  }
    332     //}
    333 
    334     //public void UpdateRunStatus(long runId, ProcessStatus status) {
    335     //  rwLock.EnterWriteLock();
    336     //  try {
    337     //    using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
    338     //      cnn.Open();
    339     //      using(SQLiteTransaction t = cnn.BeginTransaction()) {
    340     //        using(SQLiteCommand c = cnn.CreateCommand()) {
    341     //          c.Transaction = t;
    342     //          c.CommandText = "Update Run set Status=@Status where id=@Id";
    343     //          DbParameter statusParam = c.CreateParameter();
    344     //          DbParameter idParam = c.CreateParameter();
    345     //          statusParam.ParameterName = "@Status";
    346     //          statusParam.Value = status;
    347     //          idParam.ParameterName = "@Id";
    348     //          idParam.Value = runId;
    349     //          c.Parameters.Add(statusParam);
    350     //          c.Parameters.Add(idParam);
    351     //          c.ExecuteNonQuery();
    352     //        }
    353     //        t.Commit();
    354     //      }
    355     //    }
    356     //  } finally {
    357     //    rwLock.ExitWriteLock();
    358     //  }
    359     //}
    360284    #endregion
    361285
     
    372296          DbParameter statusParameter = c.CreateParameter();
    373297          statusParameter.ParameterName = "@Status";
    374           statusParameter.Value = status;
     298          statusParameter.Value = status.ToString();
    375299          c.Parameters.Add(statusParameter);
    376300
     
    448372      return agents;
    449373    }
    450 
    451     //public ICollection<RunEntry> GetRuns(long agentId) {
    452     //  List<RunEntry> runs = new List<RunEntry>();
    453     //  rwLock.EnterReadLock();
    454     //  try {
    455     //    using(DbConnection cnn = new SQLiteConnection(connectionString)) {
    456     //      cnn.Open();
    457     //      using(DbCommand c = cnn.CreateCommand()) {
    458     //        c.CommandText = "Select Id, AgentId, CreationTime, Status, Rawdata from Run where AgentId=@AgentId";
    459     //        DbParameter agentParameter = c.CreateParameter();
    460     //        agentParameter.ParameterName = "@AgentId";
    461     //        agentParameter.Value = agentId;
    462     //        c.Parameters.Add(agentParameter);
    463 
    464     //        using(DbDataReader r = c.ExecuteReader()) {
    465     //          while(r.Read()) {
    466     //            RunEntry run = new RunEntry();
    467     //            run.Id = r.GetInt32(0);
    468     //            run.AgentId = r.GetInt32(1);
    469     //            run.CreationTime = r.GetDateTime(2);
    470     //            run.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(3));
    471     //            run.RawData = (byte[])r.GetValue(4);
    472     //            runs.Add(run);
    473     //          }
    474     //        }
    475     //      }
    476     //    }
    477     //  } finally {
    478     //    rwLock.ExitReadLock();
    479     //  }
    480     //  return runs;
    481     //}
    482 
    483     //public ICollection<RunEntry> GetRuns(ProcessStatus status) {
    484     //  List<RunEntry> runs = new List<RunEntry>();
    485     //  rwLock.EnterReadLock();
    486     //  try {
    487     //    using(DbConnection cnn = new SQLiteConnection(connectionString)) {
    488     //      cnn.Open();
    489     //      using(DbCommand c = cnn.CreateCommand()) {
    490     //        c.CommandText = "Select Id, AgentId, CreationTime, Status, Rawdata from Run where Status=@Status";
    491     //        DbParameter statusParameter = c.CreateParameter();
    492     //        statusParameter.ParameterName = "@Status";
    493     //        statusParameter.Value = status;
    494     //        c.Parameters.Add(statusParameter);
    495 
    496     //        using(DbDataReader r = c.ExecuteReader()) {
    497     //          while(r.Read()) {
    498     //            RunEntry run = new RunEntry();
    499     //            run.Id = r.GetInt32(0);
    500     //            run.AgentId = r.GetInt32(1);
    501     //            run.CreationTime = r.GetDateTime(2);
    502     //            run.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(3));
    503     //            run.RawData = (byte[])r.GetValue(4);
    504     //            runs.Add(run);
    505     //          }
    506     //        }
    507     //      }
    508     //    }
    509     //  } finally {
    510     //    rwLock.ExitReadLock();
    511     //  }
    512     //  return runs;
    513     //}
    514374
    515375    public ICollection<ResultEntry> GetResults(long agentId) {
  • trunk/sources/HeuristicLab.CEDMA.Server/RunScheduler.cs

    r390 r392  
    4545    private object queueLock = new object();
    4646    private Queue<Job> jobQueue;
     47    private AutoResetEvent runningJobs = new AutoResetEvent(false);
    4748
    4849    public RunScheduler(Database database, JobManager jobManager) {
     
    8081        lock(queueLock) {
    8182          jobQueue.Enqueue(job);
     83          runningJobs.Set();
    8284        }
    8385      }
     
    8789      try {
    8890        while(true) {
    89           int runningJobs;
    90           lock(queueLock) runningJobs = jobQueue.Count;
    91           if(runningJobs==0) Thread.Sleep(1000); // TASK: replace with waithandle
     91          Job job = null;
     92          lock(queueLock) if(jobQueue.Count > 0) job = jobQueue.Dequeue();
     93          if(job == null) runningJobs.WaitOne();
    9294          else {
    93             Job job;
    94             lock(queueLock) {
    95               job = jobQueue.Dequeue();
    96             }
    9795            job.WaitHandle.WaitOne();
    9896            job.WaitHandle.Close();
    9997            lock(remoteCommLock) {
    100               jobManager.EndExecuteOperation(job.Operation);
    101               database.UpdateAgent(job.AgentId, ProcessStatus.Finished);
     98              try {
     99                jobManager.EndExecuteOperation(job.Operation);
     100                database.UpdateAgent(job.AgentId, ProcessStatus.Finished);
     101              } catch(JobExecutionException ex) {
     102                database.UpdateAgent(job.AgentId, ProcessStatus.Error);
     103              }
    102104            }
    103105          }
Note: See TracChangeset for help on using the changeset viewer.