コード例 #1
0
ファイル: airport.cpp プロジェクト: bububa/Airport
/* RUN AS AIRPORT */
void 
run_as_airport(const int max_concurrent_jobs, std::string &alias)
{
    while(true)
    {
        if (airport::License::expired())
        {
            std::cout << "Your license has been expired." << std::endl;
            return;
        }
        {
            airport::Mongo mongoDB;
            mongo::DBClientConnection mongoConnection;
            mongoDB.connect(&mongoConnection);
            mongoDB.mountServer(mongoConnection, alias);
            mongoConnection.ensureIndex(MONGO_DISPATCHER_COLLECTION, mongo::fromjson("{servername:1, rulename:1, completed_datetime:1, archived:1}"));
            int status;
            std::map<pid_t, std::string> running_processes;
            check_jobs(alias, running_processes, max_concurrent_jobs);
            while(!running_processes.empty())
            {
                pid_t pid = wait(&status);
                if (pid == -1) break;
                std::string rulename = running_processes[pid];
                //std::cout << "PID: " << pid << " RULE: "<< rulename <<" finished." << std::endl;
                std::map<pid_t, std::string>::iterator it;
                it=running_processes.find(pid);
                running_processes.erase(it);
                airport::Rule rule;
                std::string filepath = airport::DATA_PATH + "rules/" + rulename;
                std::string rulecontent = rule.readinfo(filepath);
                mongoDB.serverJobComplete(mongoConnection, alias, rulename, rulecontent);
                check_jobs(alias, running_processes, max_concurrent_jobs);
            }
        }
        std::cout << "sleeping..." << std::endl;
        sleep(30);
    }
}
コード例 #2
0
int main(int argc , char ** argv) {
  const int queue_timeout =  180;
  const int submit_timeout = 180;
  const int status_timeout = 180;
  const int number_of_jobs = 250;
  const int submit_threads = number_of_jobs / 10 ;
  const int status_threads = number_of_jobs + 1;
  const char * job = util_alloc_abs_path(argv[1]);
  rng_type * rng = rng_alloc( MZRAN , INIT_CLOCK );
  test_work_area_type * work_area = test_work_area_alloc("job_queue");
  job_type **jobs = alloc_jobs( rng , number_of_jobs , job);

  job_queue_type * queue = job_queue_alloc(number_of_jobs, "OK", "ERROR");
  queue_driver_type * driver = queue_driver_alloc_local();
  job_queue_manager_type * queue_manager = job_queue_manager_alloc( queue );

  job_queue_set_driver(queue, driver);
  job_queue_manager_start_queue(queue_manager, 0, false , true);

  {
    thread_pool_type * status_pool = thread_pool_alloc( status_threads , true );
    thread_pool_type * submit_pool = thread_pool_alloc( submit_threads , true );

    submit_jobs( queue , number_of_jobs , jobs , submit_pool );
    status_jobs( queue , number_of_jobs , jobs , status_pool );

    if (!thread_pool_try_join( submit_pool , submit_timeout ))
      util_exit("Joining submit pool failed \n");
    thread_pool_free( submit_pool );

    job_queue_submit_complete(queue);

    if (!thread_pool_try_join( status_pool , status_timeout))
      util_exit("Joining status pool failed \n");
    thread_pool_free( status_pool );
  }

  if (!job_queue_manager_try_wait(queue_manager , queue_timeout))
    util_exit("job_queue never completed \n");

  job_queue_manager_free(queue_manager);
  job_queue_free(queue);
  queue_driver_free(driver);
  check_jobs( number_of_jobs , jobs );
  test_work_area_free(work_area);
  rng_free( rng );
}