Add small library for running jobs with different programs

This commit is contained in:
Eike Foken
2011-08-30 01:10:42 +02:00
parent cc7ac2f47b
commit 5aaef1fc62
2 changed files with 88 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
<?php
class Program_runner {
private $CI;
/**
* Constructor.
*
* @param array $params
*/
public function __construct($params = array()) {
$defaults = array('program_driver' => 'scatt');
foreach ($defaults as $key => $val) {
if (isset($params[$key]) && $params[$key] !== "") {
$defaults[$key] = $params[$key];
}
}
extract($defaults);
$this->CI =& get_instance();
// load the requested programs library
$this->CI->load->library('programs/' . $program_driver, array());
// make calc to refer to current library
$this->driver =& $this->CI->$program_driver;
log_message('debug', "Program Runner Class Initialized and loaded. Driver used: " . $program_driver);
}
/**
* Creates a job from the specified trial.
*
* @param string $trialId
*/
public function createJob($trialId) {
if ($this->driver->_createJob($trialId)) {
$this->CI->load->model('job');
$this->CI->job->create(array('trial_id' => $trialId, 'started_by' => $this->CI->session->userdata('user_id')));
}
return true;
}
}

View File

@@ -0,0 +1,42 @@
<?php
/**
*
* @author Eike Foken <kontakt@eikefoken.de>
*/
class Scatt extends Program_runner {
/**
*
* @param unknown_type $params
*/
public function __construct($params) {
$this->CI =& get_instance();
extract($params);
$this->CI->load->model('program');
$this->program = $this->CI->program->getByDriver(strtolower(__CLASS__));
log_message('debug', "Scatt Class Initialized");
}
/**
*
* @param unknown_type $trialId
*/
public function _createJob($trialId) {
$this->CI->load->library('parser');
$trial = $this->CI->trial->getById($trialId);
$path = FCPATH . 'uploads/' . $trial['project_id'] . '/' . $trial['id'] . '/';
$handler = fopen($path . 'default.calc', "w");
$data['parameters'] = $this->CI->trial->getParameters($trialId);
@fwrite($handler, $this->CI->parser->parse_string($this->program['config_template'], $data, true));
@fclose($handler);
return true;
}
}