Changeset 392
- Timestamp:
- 07/22/08 21:16:39 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/AgentEntry.cs
r390 r392 37 37 public string Name { get; set; } 38 38 [DataMember] 39 public DateTime CreationTime { get; set; } 40 [DataMember] 39 41 public ProcessStatus Status { get; set; } 40 42 [DataMember] -
trunk/sources/HeuristicLab.CEDMA.DB/Database.cs
r390 r392 55 55 } 56 56 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)"; 58 58 cmd.Transaction = t; 59 59 cmd.ExecuteNonQuery(); … … 83 83 using(DbCommand c = cnn.CreateCommand()) { 84 84 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()"; 86 86 DbParameter nameParam = c.CreateParameter(); 87 87 nameParam.ParameterName = "@Name"; … … 96 96 controllerParam.Value = controllerAgent; 97 97 c.Parameters.Add(controllerParam); 98 DbParameter creationTimeParam = c.CreateParameter(); 99 creationTimeParam.ParameterName = "@CreationTime"; 100 creationTimeParam.Value = DateTime.Now; 101 c.Parameters.Add(creationTimeParam); 98 102 DbParameter dataParam = c.CreateParameter(); 99 103 dataParam.ParameterName = "@RawData"; … … 236 240 DbParameter idParam = c.CreateParameter(); 237 241 statusParam.ParameterName = "@Status"; 238 statusParam.Value = status ;242 statusParam.Value = status.ToString(); 239 243 idParam.ParameterName = "@Id"; 240 244 idParam.Value = id; … … 278 282 } 279 283 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 //}360 284 #endregion 361 285 … … 372 296 DbParameter statusParameter = c.CreateParameter(); 373 297 statusParameter.ParameterName = "@Status"; 374 statusParameter.Value = status ;298 statusParameter.Value = status.ToString(); 375 299 c.Parameters.Add(statusParameter); 376 300 … … 448 372 return agents; 449 373 } 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 //}514 374 515 375 public ICollection<ResultEntry> GetResults(long agentId) { -
trunk/sources/HeuristicLab.CEDMA.Server/RunScheduler.cs
r390 r392 45 45 private object queueLock = new object(); 46 46 private Queue<Job> jobQueue; 47 private AutoResetEvent runningJobs = new AutoResetEvent(false); 47 48 48 49 public RunScheduler(Database database, JobManager jobManager) { … … 80 81 lock(queueLock) { 81 82 jobQueue.Enqueue(job); 83 runningJobs.Set(); 82 84 } 83 85 } … … 87 89 try { 88 90 while(true) { 89 int runningJobs;90 lock(queueLock) runningJobs = jobQueue.Count;91 if( runningJobs==0) Thread.Sleep(1000); // TASK: replace with waithandle91 Job job = null; 92 lock(queueLock) if(jobQueue.Count > 0) job = jobQueue.Dequeue(); 93 if(job == null) runningJobs.WaitOne(); 92 94 else { 93 Job job;94 lock(queueLock) {95 job = jobQueue.Dequeue();96 }97 95 job.WaitHandle.WaitOne(); 98 96 job.WaitHandle.Close(); 99 97 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 } 102 104 } 103 105 }
Note: See TracChangeset
for help on using the changeset viewer.