ESPDFUWorkunit.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. define([
  17. "dojo/_base/declare",
  18. "dojo/_base/lang",
  19. "hpcc/FileSpray",
  20. "hpcc/ESPResult"
  21. ], function (declare, lang,
  22. FileSpray, ESPResult) {
  23. return declare(null, {
  24. Wuid: "",
  25. stateID: 0,
  26. state: "",
  27. text: "",
  28. resultCount: 0,
  29. results: [],
  30. graphs: [],
  31. exceptions: [],
  32. timers: [],
  33. onCreate: function () {
  34. },
  35. onUpdate: function () {
  36. },
  37. onSubmit: function () {
  38. },
  39. constructor: function (args) {
  40. declare.safeMixin(this, args);
  41. },
  42. isComplete: function () {
  43. switch (this.stateID) {
  44. case 6: //DFUStateFinished:
  45. return true;
  46. }
  47. return false;
  48. },
  49. monitor: function (callback, monitorDuration) {
  50. if (!monitorDuration)
  51. monitorDuration = 0;
  52. var context = this;
  53. FileSpray.GetDFUWorkunit({
  54. request: {
  55. wuid: this.Wuid
  56. },
  57. load: function (response) {
  58. var workunit = response.GetDFUWorkunitResponse.result;
  59. context.stateID = workunit.State;
  60. context.state = workunit.StateMessage;
  61. if (callback) {
  62. callback(workunit);
  63. }
  64. if (!context.isComplete()) {
  65. var timeout = 30; // Seconds
  66. if (monitorDuration < 5) {
  67. timeout = 1;
  68. } else if (monitorDuration < 10) {
  69. timeout = 2;
  70. } else if (monitorDuration < 30) {
  71. timeout = 5;
  72. } else if (monitorDuration < 60) {
  73. timeout = 10;
  74. } else if (monitorDuration < 120) {
  75. timeout = 20;
  76. }
  77. setTimeout(function () {
  78. context.monitor(callback, monitorDuration + timeout);
  79. }, timeout * 1000);
  80. }
  81. },
  82. error: function () {
  83. done = true;
  84. }
  85. });
  86. },
  87. fetchXML: function (onFetchXML) {
  88. FileSpray.DFUWUFile({
  89. request: {
  90. Wuid: this.Wuid
  91. },
  92. load: function (response) {
  93. onFetchXML(response);
  94. }
  95. });
  96. },
  97. create: function (ecl) {
  98. },
  99. update: function (request, appData, callback) {
  100. },
  101. submit: function (target) {
  102. },
  103. _resubmit: function (clone, resetWorkflow, callback) {
  104. },
  105. clone: function (callback) {
  106. this._resubmit(true, false, callback);
  107. },
  108. resubmit: function (callback) {
  109. this._resubmit(false, false, callback);
  110. },
  111. restart: function (callback) {
  112. this._resubmit(false, true, callback);
  113. },
  114. _action: function (action, callback) {
  115. },
  116. abort: function (callback) {
  117. this._action("Abort", callback);
  118. },
  119. doDelete: function (callback) {
  120. this._action("Delete", callback);
  121. },
  122. getInfo: function (args) {
  123. var request = {
  124. wuid: this.Wuid
  125. };
  126. var context = this;
  127. FileSpray.GetDFUWorkunit({
  128. request: {
  129. wuid: this.Wuid
  130. },
  131. load: function (response) {
  132. var workunit = response.GetDFUWorkunitResponse.result;
  133. context.GetDFUWorkunitResponse = workunit;
  134. if (args.onGetAll) {
  135. args.onGetAll(workunit);
  136. }
  137. }
  138. });
  139. },
  140. getState: function () {
  141. return this.state;
  142. },
  143. getProtectedImage: function () {
  144. if (this.protected) {
  145. return "img/locked.png"
  146. }
  147. return "img/unlocked.png"
  148. },
  149. getStateImage: function () {
  150. switch (this.stateID) {
  151. case 6:
  152. return "img/workunit_completed.png";
  153. }
  154. return "img/workunit.png";
  155. }
  156. });
  157. });