Skip to content

Commit 0659c5d

Browse files
committed
Job history viewer added
1 parent 1dee523 commit 0659c5d

14 files changed

Lines changed: 208 additions & 36 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ composer.lock
3232
/deb/
3333
/nbproject/private/
3434
/OpenAPI/node_modules/
35+
/.php_cs.cache
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Phinx\Migration\AbstractMigration;
6+
7+
final class JobOutput extends AbstractMigration
8+
{
9+
/**
10+
* Change Method.
11+
*
12+
* Write your reversible migrations using this method.
13+
*
14+
* More information on writing migrations is available here:
15+
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
16+
*
17+
* Remember to call "create()" or "update()" and NOT "save()" when working
18+
* with the Table class.
19+
*/
20+
public function change(): void
21+
{
22+
$table = $this->table('job');
23+
$table
24+
->addColumn('stdout', 'text', ['null' => true, 'default' => null])
25+
->addColumn('stderr', 'text', ['null' => true, 'default' => null])
26+
->save();
27+
28+
}
29+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Phinx\Migration\AbstractMigration;
6+
7+
final class LaunchedBy extends AbstractMigration
8+
{
9+
/**
10+
* Change Method.
11+
*
12+
* Write your reversible migrations using this method.
13+
*
14+
* More information on writing migrations is available here:
15+
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
16+
*
17+
* Remember to call "create()" or "update()" and NOT "save()" when working
18+
* with the Table class.
19+
*/
20+
public function change(): void
21+
{
22+
$table = $this->table('job');
23+
$table
24+
->addColumn('launched_by', 'text', ['null' => true, 'default' => null,'comment'=>'launchd by'])
25+
->save();
26+
27+
}
28+
}

debian/changelog

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
multiflexi (1.3.0) UNRELEASED; urgency=medium
1+
multiflexi (1.4.0) UNRELEASED; urgency=medium
22

33
[ CyberVitexus ]
44
* Ability choose run interval between hour and year
@@ -23,8 +23,9 @@ multiflexi (1.3.0) UNRELEASED; urgency=medium
2323
[ vitex ]
2424
* executor rewrited
2525
* provisioning added
26+
* Job Output archived now
2627

27-
-- vitex <info@vitexsoftware.cz> Sat, 18 Mar 2023 11:23:01 +0100
28+
-- vitex <info@vitexsoftware.cz> Mon, 20 Mar 2023 16:49:44 +0100
2829

2930
multiflexi (0.1) experimental; urgency=medium
3031

debian/conf/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vitexsoftware/multiflexi",
33
"description": "Tool used to setup AbraFlexi multiinstance",
4-
"version": "1.2.1",
4+
"version": "1.4.0",
55
"type": "project",
66
"require": {
77
"deb/ease-bootstrap4-widgets-abraflexi": "*",

lib/executor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
}
8585
});
8686
$app->addStatusMessage('end' . $exec . '@' . $app->getDataValue('name'));
87-
$jobber->runEnd($runId, $process->getExitCode());
87+
$jobber->runEnd($runId, $process->getExitCode(), $process->getOutput(), $process->getErrorOutput());
8888
$companer->addStatusMessage('command end: ' . $exec . '@' . $company['nazev']);
8989
}
9090
}

src/AbraFlexi/MultiFlexi/AppToCompany.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function getAppEnvironment() {
8585
'ABRAFLEXI_PASSWORD' => $connectionData['password'],
8686
'ABRAFLEXI_COMPANY' => $connectionData['company'],
8787
'EASE_EMAILTO' => $connectionData['email'],
88-
'EASE_LOGGER' => empty($connectionData['email']) ? 'syslog' : 'syslog|email',
88+
'EASE_LOGGER' => 'syslog|console',
8989
];
9090

9191
$appConfig = [];

src/AbraFlexi/MultiFlexi/Job.php

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Job extends Engine {
2828
*/
2929
public function runBegin($appId, $companyId) {
3030
$jobId = $this->insertToSQL(['company_id' => $companyId, 'app_id' => $appId,
31-
'exitcode' => 255]);
31+
'exitcode' => -1, 'launched_by' => \Ease\Shared::user()->getMyKey()]);
3232
$this->setMyKey($jobId);
3333
$this->setObjectName();
3434
$sqlLogger = LogToSQL::singleton();
@@ -40,29 +40,30 @@ public function runBegin($appId, $companyId) {
4040
$this->addStatusMessage(_('Perform initial setup'), 'warning');
4141
$app = new Application((int) $appId);
4242
$setupCommand = $app->getDataValue('setup');
43-
44-
$appCompany = new AppToCompany();
45-
$appCompany->setMyKey($appCompany->appCompanyID( $appId,$companyId));
46-
$appInfo = $appCompany->getAppInfo();
47-
$appEnvironment = $appCompany->getAppEnvironment();
48-
$process = new \Symfony\Component\Process\Process(explode(' ', $setupCommand), null, $appEnvironment, null, 32767);
49-
50-
$result = $process->run(function ($type, $buffer) {
51-
$logger = new Runner();
52-
if (\Symfony\Component\Process\Process::ERR === $type) {
53-
$outline = (new \SensioLabs\AnsiConverter\AnsiToHtmlConverter())->convert($buffer);
54-
$logger->addStatusMessage($buffer, 'error');
55-
} else {
56-
$logger->addStatusMessage($buffer, 'success');
57-
$outline = (new \SensioLabs\AnsiConverter\AnsiToHtmlConverter())->convert($buffer);
43+
if (!empty(trim($setupCommand))) {
44+
$app->addStatusMessage(_('Setup command') . ': ' . $setupCommand, 'debug');
45+
$appCompany = new AppToCompany();
46+
$appCompany->setMyKey($appCompany->appCompanyID($appId, $companyId));
47+
$appInfo = $appCompany->getAppInfo();
48+
$appEnvironment = $appCompany->getAppEnvironment();
49+
$process = new \Symfony\Component\Process\Process(explode(' ', $setupCommand), null, $appEnvironment, null, 32767);
50+
51+
$result = $process->run(function ($type, $buffer) {
52+
$logger = new Runner();
53+
if (\Symfony\Component\Process\Process::ERR === $type) {
54+
$outline = (new \SensioLabs\AnsiConverter\AnsiToHtmlConverter())->convert($buffer);
55+
$logger->addStatusMessage($buffer, 'error');
56+
} else {
57+
$logger->addStatusMessage($buffer, 'success');
58+
$outline = (new \SensioLabs\AnsiConverter\AnsiToHtmlConverter())->convert($buffer);
59+
}
60+
echo new \Ease\Html\DivTag(nl2br($outline));
61+
});
62+
if ($result == 0) {
63+
$appCompany->setProvision(1);
64+
$this->addStatusMessage('provision done', 'success');
5865
}
59-
echo new \Ease\Html\DivTag(nl2br($outline));
60-
});
61-
if($result == 0){
62-
$appCompany->setProvision(1);
63-
$this->addStatusMessage('provision done', 'success');
6466
}
65-
6667
}
6768

6869
return $jobId;
@@ -76,11 +77,13 @@ public function runBegin($appId, $companyId) {
7677
*
7778
* @return int
7879
*/
79-
public function runEnd($runId, $statusCode) {
80+
public function runEnd($runId, $statusCode, $stdout, $stderr) {
8081
$sqlLogger = LogToSQL::singleton();
8182
$sqlLogger->setCompany(0);
8283
$sqlLogger->setApplication(0);
8384
return $this->updateToSQL(['end' => new \Envms\FluentPDO\Literal('NOW()'),
85+
'stdout' => $stdout,
86+
'stderr' => $stderr,
8487
'exitcode' => $statusCode], ['id' => $runId]);
8588
}
8689

@@ -94,7 +97,7 @@ public function runEnd($runId, $statusCode) {
9497
*/
9598
public function isProvisioned($appId, $companyId) {
9699
$appCompany = new AppToCompany();
97-
$appCompany->setMyKey($appCompany->appCompanyID( $appId,$companyId));
100+
$appCompany->setMyKey($appCompany->appCompanyID($appId, $companyId));
98101
$appInfo = $appCompany->getAppInfo();
99102
return $appInfo['prepared'];
100103
}

src/AbraFlexi/MultiFlexi/Ui/PageBottom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function finalize() {
4040
$this->addItem('<hr>');
4141
$footrow = new \Ease\TWB4\Row();
4242

43-
$author = 'Multi Flexi v.: ' . $appInfo->version . (empty(self::BUILD) ? '' : '&nbsp;'._('build'). ' #'.self::BUILD) . '&nbsp;&nbsp; &copy; 2020-2021 <a href="https://vitexsoftware.cz/">Vitex Software</a>';
43+
$author = 'Multi Flexi v.: ' . $appInfo->version . (empty(self::BUILD) ? '' : '&nbsp;'._('build'). ' #'.self::BUILD) . '&nbsp;&nbsp; &copy; 2020-2023 <a href="https://vitexsoftware.cz/">Vitex Software</a>';
4444

4545
$footrow->addColumn(6, [$author]);
4646

src/AbraFlexi/MultiFlexi/Ui/ServicesForCompanyForm.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public function __construct($company, $tagProperties = array()) {
4141
$assigned = $glue->getAppsForCompany($companyID);
4242
parent::__construct($tagProperties);
4343

44+
$jobber = new \AbraFlexi\MultiFlexi\Job();
45+
4446
foreach ($apps as $appData) {
4547
$code = $appData['id'];
4648

@@ -54,13 +56,21 @@ public function __construct($company, $tagProperties = array()) {
5456
if (array_key_exists($code, $assigned)) {
5557
$launchButton = new \Ease\Html\DivTag(new LaunchButton($assigned[$code]['id']));
5658
} else {
57-
// $launchButton = new \Ease\TWB4\LinkButton('id=' . $code . '&company=' . $companyID, sprintf(_('Assign to %s'), $_SESSION['company']->getRecordName()), 'success');
58-
$launchButton = null;
59+
$launchButton = new \Ease\TWB4\LinkButton('launch.php?app_id='.$code.'&company_id=' . $companyID, [_('Launch') . '&nbsp;&nbsp;', new \Ease\Html\ImgTag('images/rocket.svg', _('Launch'), ['height' => '30px'])], 'warning btn-lg btn-block ');
5960
}
6061

6162
$appRow->addColumn(4, new FormGroup('<strong>' . $appData['nazev'] . '</strong> ', $intervalChooser))->addItem($launchButton);
6263

63-
$appRow->addColumn(6, [new ConfiguredFieldBadges($companyID, $code)]);
64+
$jobs = $jobber->listingQuery()->select(['id','begin','exitcode'],true)->where('company_id',$companyID)->where('app_id',$code)->limit(10)->fetchAll();
65+
66+
$jobList = new \Ease\TWB4\Table();
67+
$jobList->addRowHeaderColumns([_('Job ID'),_('Launch time'),_('Exit Code')]);
68+
foreach ($jobs as $job) {
69+
$job['id'] = new ATag('job.php?id='.$job['id'], $job['id']);
70+
$jobList->addRowColumns($job);
71+
}
72+
73+
$appRow->addColumn(6, [new ConfiguredFieldBadges($companyID, $code),$jobList]);
6474

6575
$this->addItem($appRow);
6676
}

0 commit comments

Comments
 (0)