SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/views/admin/worker_job_edit.php

  1. <?php
  2. /*
  3.  * kate: tab-width 4; indent-width 4; space-indent on; word-wrap off; word-wrap-column 120;
  4.  * :tabSize=4:indentSize=4:noTabs=true:wrap=false:maxLineLen=120:mode=php:
  5.  *
  6.  * Copyright (C) 2015 Karmabunny Pty Ltd.
  7.  *
  8.  * This file is a part of SproutCMS.
  9.  *
  10.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  11.  * of the GNU General Public License as published by the Free Software Foundation, either
  12.  * version 3 of the License, or (at your option) any later version.
  13.  *
  14.  * For more information, visit <http://getsproutcms.com>.
  15.  */
  16.  
  17. use Sprout\Helpers\Constants;
  18. use Sprout\Helpers\Enc;
  19. use Sprout\Helpers\File;
  20. ?>
  21.  
  22. <?php if (!empty($data['name'])): ?>
  23. <p><b>Name:</b>
  24. <br><?= Enc::html($data['name']); ?></p>
  25. <?php endif; ?>
  26.  
  27. <?php if (!empty($data['status'])): ?>
  28. <p><b>Status:</b>
  29. <br><span class="job-status"><?= Enc::html($data['status']); ?></span></p>
  30. <?php endif; ?>
  31.  
  32. <?php if (!empty($data['date_started'])): ?>
  33. <p><b>Date started:</b>
  34. <br><?= Enc::html($data['date_started']); ?></p>
  35. <?php endif; ?>
  36.  
  37. <?php if (!empty($data['args'])): ?>
  38. <p><b>Arguments:</b></p>
  39. <pre><?= Enc::html(print_r(json_decode($data['args'], true), true)); ?></pre>
  40. <?php endif; ?>
  41.  
  42. <!-- Completed or failed -->
  43. <?php if (!empty($data['date_success'])): ?>
  44. <p><b>Completed:</b>
  45. <br><?= Enc::html($data['date_success']); ?></p>
  46. <?php elseif (!empty($data['date_failure'])): ?>
  47. <p><b>Failed:</b>
  48. <br><?= Enc::html($data['date_failure']); ?></p>
  49. <?php endif; ?>
  50.  
  51. <!-- If running, PID and mem use -->
  52. <?php if (!empty($data['pid'])): ?>
  53. <p><b>PID:</b>
  54. <br><?= Enc::html($data['pid']); ?></p>
  55. <?php endif; ?>
  56.  
  57. <?php if (!empty($data['memuse'])): ?>
  58. <p><b>RAM usage:</b>
  59. <br><?= Enc::html(File::humanSize($data['memuse'])); ?></p>
  60. <?php endif; ?>
  61.  
  62. <!-- Metrics -->
  63. <?php if (!empty($data['metric1name'])): ?>
  64. <p><b><?= Enc::html($data['metric1name']); ?>:</b>
  65. <br><span class="job-metric1"><?= Enc::html($data['metric1val']); ?></span></p>
  66. <?php endif; ?>
  67.  
  68. <?php if (!empty($data['metric2name'])): ?>
  69. <p><b><?= Enc::html($data['metric2name']); ?>:</b>
  70. <br><span class="job-metric2"><?= Enc::html($data['metric2val']); ?></span></p>
  71. <?php endif; ?>
  72.  
  73. <?php if (!empty($data['metric3name'])): ?>
  74. <p><b><?= Enc::html($data['metric3name']); ?>:</b>
  75. <br><span class="job-metric3"><?= Enc::html($data['metric3val']); ?></span></p>
  76. <?php endif; ?>
  77.  
  78. <h3>Log</h3>
  79. <pre class="log"><?= Enc::html(@$data['log']); ?></pre>
  80.  
  81. <script>
  82. $(document).ready(function() {
  83. var intervalID;
  84. var status_names = <?= json_encode(Constants::$job_status); ?>;
  85.  
  86. function updateStatus() {
  87. $.getJSON(SITE + 'admin/call/worker_job/jsonStatus/' + <?= Enc::js($id); ?>, function(data) {
  88. $('.job-status').text(status_names[data.status]);
  89. if ($('.job-metric1').length) $('.job-metric1').text(data.metric1val);
  90. if ($('.job-metric2').length) $('.job-metric2').text(data.metric2val);
  91. if ($('.job-metric3').length) $('.job-metric3').text(data.metric3val);
  92. $('pre.log').text(data.log);
  93.  
  94. if (data.status != 'Running') window.clearInterval(intervalID);
  95. });
  96. }
  97.  
  98. intervalID = window.setInterval(updateStatus, 1000);
  99. });
  100. </script>
  101.