Skip to content
Permalink
Browse files

"Run on all active hosts" added for scheduler executions and queueing…

… function
  • Loading branch information...
tvannini committed Sep 18, 2019
1 parent bd01844 commit 120a327e4bf5a099783fbc88eb2a8e4087e2cdd6
Showing with 164 additions and 41 deletions.
  1. +5 −0 jxconv.php
  2. +81 −13 lib/jxapp.inc
  3. +7 −2 lib/jxfnx.inc
  4. +37 −15 lib/prgs/jxtask.prf
  5. +11 −11 lib/prgs/jxtask.prg
  6. +23 −0 lib/prgs/tables.inc
@@ -939,6 +939,11 @@ static function to2_6($app_name, $app_dir) {
'host',
'host',
'jxhost');
$code = add_tab_field($code,
'jx_scheduler',
'sched_all_hosts',
'sched_all_hosts',
'_o2logical');
// ____________________________________________ Write down new repository code ___
file_put_contents($app_dir.'prgs'.DIRECTORY_SEPARATOR.$tables, $code);
@@ -4029,6 +4029,22 @@ class o2_run_job {
$sched_id = 0,
$host = false) {
// _________________________________________________ Queue on all active hosts ___
if ($host == '*') {
$list = array();
foreach (o2_service::get_hosts() as $host) {
$list[] = self::queue($job,
$run_params,
$aspid,
$service,
$at_date,
$at_time,
$sched_id,
$host);
}
return $list;
}
// ___________________________________________ Queue on single host or service ___
$app = $_SESSION['o2_app'];
$run_job = new o2_run_job();
$run_job->id = $app->runtime->microtime();
@@ -5341,6 +5357,42 @@ class o2_service {
}
/**
* Returns a list of registered (active) hosts
*
* @return array
*/
static function get_hosts() {
$app = $_SESSION['o2_app'];
$tab = $app->get_table(self::$srv_table);
$db = $tab->db;
$server = $db->server;
$co = constant('o2_'.$server->type.'_o');
$cc = constant('o2_'.$server->type.'_c');
$f = $tab->campi;
$select = 'DISTINCT '.$f['srv_host'].' '.$co.'SRV_HOST'.$cc;
$srv_recs = o2_gateway::recordset($server->type,
$server->server,
$server->user,
$server->password,
$db->nome,
$db->proprietario,
$tab->nome,
'jx_services',
$select,
'',
'',
1000);
$list = array();
foreach ($srv_recs as $srv_rec) {
$list[] = $srv_rec['SRV_HOST'];
}
return $list;
}
/**
* Returns a list of matching services and hosts ready to be used as a TreeView
* control items
@@ -5750,6 +5802,7 @@ class o2_task {
public $month_day = 0;
public $description = "";
public $aspid = false;
public $all_hosts = false;
public $paused = false;
@@ -5764,7 +5817,8 @@ class o2_task {
$week_day = "",
$month_day = 0,
$aspid = false,
$paused = false) {
$paused = false,
$all_hosts = false) {
$this->id = intval($id);
$this->job = intval($job);
@@ -5777,6 +5831,7 @@ class o2_task {
$this->week_day = $week_day;
$this->month_day = intval($month_day);
$this->aspid = $aspid;
$this->all_hosts = $all_hosts;
$this->paused = $paused;
}
@@ -5817,6 +5872,7 @@ class o2_task {
$tab->campi["sched_week_day"]->nome_fisico,
$tab->campi["sched_month_day"]->nome_fisico,
$tab->campi["sched_aspid"]->nome_fisico,
$tab->campi["sched_all_hosts"]->nome_fisico,
$tab->campi["sched_paused"]->nome_fisico);
$id_val = ($this->id ? $this->id :
(count($exists) ?
@@ -5834,6 +5890,7 @@ class o2_task {
"'".$this->week_day."'",
$this->month_day,
"'".$this->aspid."'",
"'".($this->all_hosts ? '1' : '0')."'",
"'".($this->paused ? '1' : '0')."'");
o2_gateway::insertrec($server->type,
$server->server,
@@ -5885,9 +5942,10 @@ class o2_task {
$tab->campi["sched_week_day"]->nome_fisico => "'".$this->week_day."'",
$tab->campi["sched_month_day"]->nome_fisico => $this->month_day,
$tab->campi["sched_aspid"]->nome_fisico => "'".$this->aspid."'",
$tab->campi["sched_paused"]->nome_fisico => "'".
($this->paused ?
'1' : '0')."'"
$tab->campi["sched_all_hosts"]->nome_fisico => "'".($this->all_hosts ?
'1' : '0')."'",
$tab->campi["sched_paused"]->nome_fisico => "'".($this->paused ?
'1' : '0')."'"
);
$where = $tab->campi["sched_id"]->nome_fisico."=".$this->id;
$res = o2_gateway::modifyrec($server->type,
@@ -6403,6 +6461,7 @@ class o2_scheduler {
$f["sched_week_day"]." ".$co."SCHED_WEEK_DAY".$cc.",".
$f["sched_month_day"]." ".$co."SCHED_MONTH_DAY".$cc.",".
$f["sched_aspid"]." ".$co."SCHED_ASPID".$cc.",".
$f["sched_all_hosts"]." ".$co."SCHED_ALL_HOSTS".$cc.",".
$f["sched_paused"]." ".$co."SCHED_PAUSED".$cc;
$where = $f["sched_id"]."='".$sched_id."'";
$rec = o2_gateway::recordset($server->type,
@@ -6430,7 +6489,8 @@ class o2_scheduler {
$rec["SCHED_WEEK_DAY"],
$rec["SCHED_MONTH_DAY"],
$rec["SCHED_ASPID"],
$rec["SCHED_PAUSED"] === '1');
$rec["SCHED_PAUSED"] === '1',
$rec["SCHED_ALL_HOSTS"] === '1');
}
else {
return false;
@@ -6531,6 +6591,7 @@ class o2_scheduler {
$f['sched_week_day'].' '.$co.'SCHED_WEEK_DAY'.$cc.','.
$f['sched_month_day'].' '.$co.'SCHED_MONTH_DAY'.$cc.','.
$f['sched_aspid'].' '.$co.'SCHED_ASPID'.$cc.','.
$f['sched_all_hosts'].' '.$co.'SCHED_ALL_HOSTS'.$cc.','.
$f['sched_paused'].' '.$co.'SCHED_PAUSED'.$cc;
$where = $f['sched_paused']."<>'1'";
$s_list = o2_gateway::recordset($server->type,
@@ -6551,21 +6612,28 @@ class o2_scheduler {
$ret = array();
$srvs = o2_service::get_all_host_services();
foreach ($s_list as $s_idx => $sched_rec) {
if ($app->service_redirect) {
$service = $app->service_redirect;
if ($sched_rec['SCHED_ALL_HOSTS'] != '1') {
if ($app->service_redirect) {
$service = $app->service_redirect;
}
else {
$job = o2_job::get_by_id($sched_rec['SCHED_JOB']);
$service = $job->service;
}
if (!isset($srvs[$service])) {
continue;
}
$host = '';
}
else {
$job = o2_job::get_by_id($sched_rec['SCHED_JOB']);
$service = $job->service;
}
if (!isset($srvs[$service])) {
continue;
$host = $app->host;
}
$todo = false;
$last_run = o2_run_job::get_last_job($sched_rec['SCHED_JOB'],
$sched_rec['SCHED_ASPID'],
'',
$sched_rec['SCHED_ID']);
$sched_rec['SCHED_ID'],
$host);
$last = new DateTime();
$last->setTimestamp($last_run ? $last_run->start : 0);
switch ($sched_rec['SCHED_TYPE']) {
@@ -1512,6 +1512,7 @@ function o2job_enable($job_name, $on = true) {
* program called by job.
* If a host name is provided then execution is assigned directly to that host, regardless
* of services logics.
* If "*" (star) is passed for host parameter then job is queued for all active hosts.
* NOTE: If no host name is provided execution can be assigned to local host by
* application settings: see "jobs_use_local_host" parameter in application
* settings.
@@ -1708,6 +1709,7 @@ function o2job_proc_kill($runjob_id) {
* @param string $week_day Day of week [Mon|Tue|Wed|Thu|Fri|Sat|Sun]
* @param integer $month_day Day of month [0-31]
* @param string $aspid ASPI-ID to run job for
* @param boolean $all_hosts Run job on all active hosts
* @return integer
* @see o2job_create()
* @see o2job_get_by_name()
@@ -1722,7 +1724,8 @@ function o2job_schedule($job_name,
$recurrence = "D",
$week_day = "",
$month_day = 0,
$aspid = "") {
$aspid = "",
$all_hosts = false) {
if ($job = o2_job::get_by_name($job_name)) {
$app = $_SESSION["o2_app"];
@@ -1736,7 +1739,9 @@ function o2job_schedule($job_name,
$recurrence,
$week_day,
$month_day,
$aspid);
$aspid,
false,
$all_hosts);
return $task->create();
}
else {

0 comments on commit 120a327

Please sign in to comment.
You can’t perform that action at this time.