FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
job-queue-poll.js
1 /*
2  Copyright (C) 2014, Siemens AG
3  Author: Daniele Fognini, Johannes Najjar
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 var jobPollQueue = [];
20 var currentTimeout = 1000;
21 var currentTimeoutObj = "";
22 
23 function updateCheckSuccess(data) {
24  var hasFinishedJobs = false;
25  jobPollQueue = $.map(jobPollQueue, function (val) {
26  var jqId = val.jqId;
27  var callbacksuccess = val.callbacksuccess;
28  var callbackfail = val.callbackfail;
29  if ((data[jqId]) && (data[jqId].end_bits == 1)) {
30  callbacksuccess(jqId);
31  return null;
32  }
33  else if ((data[jqId]) && (data[jqId].end_bits > 1)) {
34  callbackfail(jqId);
35  return null;
36  }
37  else {
38  return val;
39  }
40  });
41  if (jobPollQueue.length > 0) {
42  if (currentTimeout < 10000) {
43  currentTimeout += 1000;
44  }
45  currentTimeout += 1000;
46  currentTimeoutObj = setTimeout(updateCheck, currentTimeout);
47  } else {
48  currentTimeoutObj = "";
49  }
50 }
51 
52 function updateCheck() {
53  if (jobPollQueue.length > 0) {
54  var jqIds = $.map(jobPollQueue, function (val) {
55  return val.jqId;
56  });
57  $.ajax({
58  type: "POST",
59  url: "?mod=jobinfo",
60  data: {"jqIds": jqIds},
61  success: updateCheckSuccess,
62  error: function () {
63  jobPollQueue = [];
64  }
65  });
66  }
67 }
68 
69 function queueUpdateCheck(jqPk, callbacksucess, callbackfail) {
70  jobPollQueue.push({"jqId": jqPk, "callbacksuccess": callbacksucess, "callbackfail": callbackfail});
71  currentTimeout = 1000;
72  if (currentTimeoutObj) {
73  clearTimeout(currentTimeoutObj);
74  }
75  currentTimeoutObj = setTimeout(updateCheck, currentTimeout);
76 }
77 
78 
79 function linkToJob(jqPk) {
80  return "<a href='?mod=showjobs&job=" + jqPk + "'>job #" + jqPk + "</a>";
81 }