API Docs for: 0.8.0
Show:

File: include/service/entities/job_service.js

  1. /*
  2. Copyright (C) 2016 PencilBlue, LLC
  3.  
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  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
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. 'use strict';
  18.  
  19. var util = require('../../util.js');
  20.  
  21. module.exports = function JobServiceModule(pb) {
  22.  
  23. /**
  24. * Provides the ability to interact with jobs that have already been created.
  25. * @class JobService
  26. * @constructor
  27. */
  28. function JobService(){
  29. this.type = 'job_run';
  30. }
  31.  
  32. /**
  33. * Retrieves the log entries for the specified job from the start date up until
  34. * the current time.
  35. * @method getLogs
  36. * @param {String} jid The job ID
  37. * @param {Date} startingDate The lower bound on the "created" field of the log
  38. * entry
  39. * @param {Function} cb A callback that takes two parameters: cb(Error, Array)
  40. */
  41. JobService.prototype.getLogs = function(jid, startingDate, cb) {
  42. if (util.isFunction(startingDate)) {
  43. cb = startingDate;
  44. startingDate = new Date(0);
  45. }
  46.  
  47. var where = {
  48. job_id: jid,
  49. created: {$gte: startingDate}
  50. };
  51. var orderBy = {'created': pb.DAO.ASC};
  52.  
  53. var dao = new pb.DAO();
  54. dao.q('job_log', {where: where, select: pb.DAO.SELECT_ALL, order: orderBy}, cb);
  55. };
  56.  
  57. /**
  58. * Retrieves the job descriptor by ID
  59. * @method loadById
  60. * @param {String} jid The job's ID
  61. * @param {Function} cb A callback that takes two parameters: cb(Error, Object)
  62. */
  63. JobService.prototype.loadById = function(jid, cb) {
  64. var dao = new pb.DAO();
  65. dao.loadById(jid, this.type, cb);
  66. };
  67.  
  68. //exports
  69. return JobService;
  70. };
  71.