diff --git a/assets/job/index.js b/assets/job/index.js index 87e13ef..a7efbf6 100644 --- a/assets/job/index.js +++ b/assets/job/index.js @@ -2,6 +2,7 @@ import 'bootstrap'; $(function() { initDeleteButtons(); + initRunNowButtons(); }) function initDeleteButtons() { @@ -20,4 +21,29 @@ function initDeleteButtons() { }) } }) +} + +function initRunNowButtons() { + $('.runnow').on('click', function() { + let me = $(this) + let href = me.data('href'); + $.ajax({ + url: href, + method: 'GET', + success: function(data) { + let modal = $('#runnow_result'); + modal.find('.modal-title').html(data.title); + if (data.status == 'deferred') { + modal.find('.modal-body').html(data.message); + } else if (data.status == 'ran') { + let content = '

Cronjob ran in ' + data.runtime + 'seconds with exit code ' + data.exitcode +'

' + content += '
' + data.output + '
' + + modal.find('.modal-body').html(content); + } + + modal.modal({show: true}) + } + }) + }) } \ No newline at end of file diff --git a/src/Repository/Job.php b/src/Repository/Job.php index d6a72f7..84ff95e 100644 --- a/src/Repository/Job.php +++ b/src/Repository/Job.php @@ -133,11 +133,11 @@ class Job extends Repository } if($job['data']['hosttype'] == 'local') { $return = $this->runLocalCommand($command); - $return['failed'] = !in_array($return['exitcode'], $job['data']['http-status']); + $return['failed'] = !in_array($return['exitcode'], $job['data']['response']); return $return; } elseif($job['data']['hosttype'] == 'ssh') { $return = $this->runSshCommand($command, $job['data']['host'], $job['data']['user'], $job['data']['ssh-privkey'], $job['data']['privkey-password']); - $return['failed'] = !in_array($return['exitcode'], $job['data']['http-status']); + $return['failed'] = !in_array($return['exitcode'], $job['data']['response']); return $return; } } @@ -235,19 +235,20 @@ class Job extends Repository public function runNow($job) { $job = $this->getJob($job, true); $runRepo = new Run($this->dbcon); - - if($runRepo->isSlowJob($job['id']) && $job['data']['crontype'] !== 'reboot') { + if($runRepo->isSlowJob($job['id']) || $job['data']['crontype'] === 'reboot') { $jobsSql = "UPDATE job SET running = :status WHERE id = :id AND running IN (0,1,2)"; $jobsStmt = $this->dbcon->prepare($jobsSql); $jobsStmt->executeQuery([':id' => $job['id'], ':status' => 2]); - return ['success' => true, 'message' => 'Job was scheduled to be run. You will find the output soon in the job details']; + return ['success' => true, 'status' => 'deferred', 'title' => 'Cronjob has been scheduled', 'message' => 'Job was scheduled to be run. You will find the output soon in the job details']; } else { $this->runJob($job['id'], true); $output = $runRepo->getLastRun($job['id']); return [ + 'status' => 'ran', 'output' => $output['output'], 'exitcode' => $output['exitcode'], 'runtime' => $output['runtime'], + 'title' => !str_contains($output['flags'], Run::FAILED) ? 'Cronjob successfully ran' : 'Cronjob failed. Please check output below', 'success' => !str_contains($output['flags'], Run::FAILED) ]; } diff --git a/templates/job/index.html.twig b/templates/job/index.html.twig index 267b1d0..da446d2 100644 --- a/templates/job/index.html.twig +++ b/templates/job/index.html.twig @@ -21,7 +21,7 @@ {{ job.interval | interval }} {{ job.nextrun | date("d/m/Y H:i:s") }} - + @@ -30,20 +30,23 @@ {% endfor %} -