Hue.JobBrowser.Poller.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. /*
  17. ---
  18. description: Adds polling functionality to the dock for JobBrowser
  19. provides: [Hue.JobBrowser.Poller]
  20. requires: [hue-shared/Hue.Dock, Core/Request.HTML, clientcide/dbug, Core/Element.Event, Core/Cookie]
  21. script: Hue.JobBrowser.Poller.js
  22. ...
  23. */
  24. if (!Hue.Dock) {
  25. dbug.warn('could not set up the jobs poller; Hue.Dock is not defined');
  26. } else {
  27. //adding a hidden ability to toggle the job poller
  28. //the console statements for the ajax requests are distracting
  29. $('hue-dock-status').addEvent('dblclick', function(){
  30. Hue.Dock[Hue.Dock.pollingJobs ? 'stopJobsPoll' : 'startJobsPoll']();
  31. Cookie.write('activateJobsPoller', Hue.Dock.pollingJobs);
  32. if (!Hue.Dock.pollingJobs) Hue.Dock.statusContent.set('html', 'poller paused');
  33. });
  34. //poll for new jobs from the job tracker
  35. //when the status notes are clicked, launch a Job Browser instance with that view
  36. Hue.Dock.statusContent.addEvents({
  37. 'click:relay(a)': function(e, a){
  38. e.preventDefault();
  39. Hue.Desktop.launch(a.get('target'), [a.get('href')]);
  40. }
  41. });
  42. $extend(Hue.Dock, {
  43. /*
  44. loads the job data into the dock
  45. */
  46. loadJobs: function(){
  47. if (Hue.Dock.pollingJobs) {
  48. Hue.Dock.statusContent.set('load', {
  49. onHueError: Hue.Dock.stopJobsPoll,
  50. onFailure: Hue.Dock.stopJobsPoll,
  51. onSuccess: Hue.Dock.loadJobs.delay(5000),
  52. url: '/status_bar/'
  53. }).load();
  54. }
  55. },
  56. startJobsPoll: function(){
  57. dbug.log('starting job poller');
  58. Hue.Dock.pollingJobs = true;
  59. Hue.Dock.loadJobs();
  60. },
  61. stopJobsPoll: function(){
  62. dbug.log('stopping job poller');
  63. Hue.Dock.statusContent.set('html', 'poller paused');
  64. Hue.Dock.pollingJobs = false;
  65. }
  66. });
  67. //whenever our poller gets an error, just stop polling
  68. Hue.Dock.statusContent.get('load').addEvent('hueError', Hue.Dock.stopJobsPoll);
  69. }