Пример #1
0
void  KKJobManager::StatusFileWrite ()
{
  log.Level (10) << "KKJobManager::StatusFileWrite" << endl;

  ofstream*  statusFile = StatusFileOpen (ios::out);

  *statusFile << "// Date/Time [" << osGetLocalDateTime () << "]." << endl
              << "//" << endl
              << endl;

  *statusFile << "Status"              << "\t" << KKJob::JobStatusToStr (status)  << endl
              << "NextJobId"           << "\t" << nextJobId                     << endl
              << "CurrentDateTime"     << "\t" << osGetLocalDateTime ()         << endl
              << "ExpansionCount"      << "\t" << expansionCount                << endl
              << "ExpansionFirstJobId" << "\t" << expansionFirstJobId           << endl
              << endl;

  kkint32  x;
  for  (x = 0;  x < jobs->QueueSize ();  x++)
  {
    KKJobPtr  j = jobs->IdxToPtr (x);
    *statusFile << "KKJob" << "\t" << j->JobType () << "\t" << j->ToStatusStr () << endl;
  }

  statusFile->flush ();
  statusFile->close ();
  delete  statusFile;

  log.Level (10) << "KKJobManager::StatusFileWrite    Exiting" << endl;
}  /* StatusFileWrite */
Пример #2
0
void  KKJobManager::StatusFileInitialize ()
{
  log.Level (10) << "KKJobManager::InializeStatusFile" << endl;

  delete  jobs;
  jobs = new KKJobList (this);

  ofstream*  statusFile = StatusFileOpen (ios::out);

  *statusFile << "// Date/Time [" << osGetLocalDateTime () << "]." << endl
              << "//" << endl
              << "//" << endl;


  *statusFile << "Status"              << "\t" << KKJob::JobStatusToStr (status)  << endl
              << "NextJobId"           << "\t" << nextJobId                     << endl
              << "CurrentDateTime"     << "\t" << osGetLocalDateTime ()         << endl
              << "ExpansionCount"      << "\t" << expansionCount                << endl
              << "ExpansionFirstJobId" << "\t" << expansionFirstJobId           << endl;

  
  StatusFileInitialize (*statusFile);  // Have derived classes do there initilization.

  delete  jobs;  jobs = NULL;
  jobs = JobsCreateInitialSet ();

  if  (jobs)
  {
    KKJobList::iterator  idx;
    for  (idx = jobs->begin ();  idx != jobs->end ();  idx++)
    {
      KKJobPtr j = *idx;
      *statusFile << "KKJob" << "\t" << j->JobType ()  << "\t" << j->ToStatusStr () << endl;
    }
  }
  else
  {
    jobs = new KKJobList (this);
  }

  statusFile->flush ();
  statusFile->close ();
  delete  statusFile;

  log.Level (10) << "KKJobManager::InializeStatusFile    Exiting" << endl;
}  /* StatusFileInitialize */
Пример #3
0
void   KKJobManager::ProcessNextExpansion (ostream&  o)
{
  KKJobListPtr jobsJustCompleted = new KKJobList (this);
  jobsJustCompleted->Owner (false);
  {
    // Add jobs completed since last expansion to this list.
    KKJobList::iterator  idx;
    for  (idx = jobs->begin ();  idx != jobs->end ();  idx++)
    {
      KKJobPtr  j = *idx;
      if  (j->JobId () >= expansionFirstJobId)
        jobsJustCompleted->PushOnBack (j);
    }
  }

  // Derived class will now peform expansion.  
  KKJobListPtr  expandedJobs = JobsExpandNextSetOfJobs (jobsJustCompleted);
  {
    if  (expandedJobs)
    {
      expandedJobs->Owner (false);
      KKJobList::iterator  idx;
      for  (idx = expandedJobs->begin ();  idx != expandedJobs->end ();  idx++)
      {
        KKJobPtr  j = *idx;
        if  (j->JobId () < expansionFirstJobId)
          expansionFirstJobId = j->JobId ();

        jobs->PushOnBack (j);
        o << "KKJob" << "\t" << j->JobType () << "\t" << j->ToStatusStr () << endl;
      }
    }
    delete  expandedJobs;
    expandedJobs = NULL;
  }

  delete  jobsJustCompleted;
  jobsJustCompleted = NULL;

  o << "NextJobId"            << "\t" << nextJobId            << endl
    << "ExpansionCount"       << "\t" << expansionCount       << endl
    << "ExpansionFirstJobId"  << "\t" << expansionFirstJobId  << endl;

}  /* ProcessNextExpansion */
Пример #4
0
KKJobListPtr  KKJobManager::GetNextSetOfJobs (KKJobListPtr  completedJobs)
{
  log.Level (20) << "KKJobManager::GetNextSetOfJobs." << endl;

  Block  ();

  StatusFileRefresh ();
 
  if  (completedJobs)
  {
    // We will first write out results of jobs that have been completed,
    ofstream* statusFile = StatusFileOpen (ios::app);

    KKJobList::iterator  idx;
    for  (idx = completedJobs->begin ();  idx != completedJobs->end ();  idx++)
    {
      KKJobPtr  j = *idx;

      *statusFile << "KKJob" << "\t" << j->JobType () << "\t" << j->ToStatusStr () << endl;
      if  (supportCompletedJobData)
      {
        *statusFile << "<KKJob JobType=" << j->JobType () << ", " << "JobId=" << j->JobId () << ">" << endl;
        j->CompletedJobDataWrite (*statusFile);
        *statusFile << "</job>" << endl;
      }

      KKJobPtr  existingJob = jobs->LookUpByJobId (j->JobId ());
      if  (existingJob)
      {
        existingJob->ReFresh (*j);
      }
      else
      {
        log.Level (-1) << endl << endl << endl
                       << "GetNextSetOfJobs     *** ERROR ***"  << endl
                       << endl
                       << "           Could not locate KKJob[" << j->JobId () << "]" << endl
                       << endl;
        return  NULL;
      }
    }

    statusFile->close ();
    delete  statusFile;  statusFile = NULL;
  }


  KKJobListPtr  jobsToExecute = new KKJobList (this);
  jobsToExecute->Owner (false);

  if  (!quitRunning)
  {
    ofstream* statusFile = StatusFileOpen (ios::app);

    KKJobPtr  nextJob = jobs->LocateOpenJob ();

    if  (!nextJob)
    {
      if  (jobs->AreAllJobsDone ())
      {
        // There are no jobs to do;  we will have to expand some existing jobs then
        ProcessNextExpansion (*statusFile);
        nextJob = jobs->LocateOpenJob ();
      }
      else
      {
        // There are still some jobs that are running.   We are going to go to
        // for now and try again later.
        //  
        // By leaving  "nextJob = NULL" we will drop strait through the rest of
        // this method and return to the caller with 'jobsToExecute' empty
        // signaling that it will need to sleep for a while before calling 
        // us again.
      }
    }

    while  (nextJob  &&  (jobsToExecute->QueueSize () < numJobsAtATime))
    {
      jobsToExecute->PushOnBack (nextJob);
      nextJob->Status (jsStarted);
      *statusFile << "JobStatusChange" << "\t" << nextJob->JobId () << "\t" << nextJob->StatusStr () << endl;
      nextJob = jobs->LocateOpenJob ();
    }

    statusFile->close ();
  }

  if  (jobsToExecute->QueueSize () < 1)
  {
    delete  jobsToExecute;
    jobsToExecute = NULL;
  }

  EndBlock ();

  log.Level (20) << "KKJobManager::GetNextSetOfJobs   Exiting." << endl;

  return  jobsToExecute;
}  /* GetNextSetOfJobs */