Socket
Socket
Sign inDemoInstall

jsreport-scheduling

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsreport-scheduling - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

28

lib/jobProcessor.js

@@ -61,3 +61,6 @@ var CronTime = require('cron').CronTime

return tasks
// someone could have deleted schedule, ignore these tasks
return tasks.filter(function (t) {
return t.schedule != null
})
})

@@ -144,9 +147,22 @@ })

}).then(function () {
return self.executionHandler(schedule, task).then(function () {
self.logger.debug('Processing schedule ' + schedule.name + ' succeeded.')
return self.documentStore.collection('tasks').update(
{_id: task._id},
return self.documentStore.collection('templates').find({shortid: schedule.templateShortid}).then(function (templates) {
if (templates.length > 0) {
return self.executionHandler(schedule, task).then(function () {
self.logger.debug('Processing schedule ' + schedule.name + ' succeeded.')
return self.documentStore.collection('tasks').update({_id: task._id},
{
$set: {
state: 'success',
finishDate: self.options.now()
}
})
})
}
self.logger.debug('Schedule template not found, marking task as error')
return self.documentStore.collection('tasks').update({_id: task._id},
{
$set: {
state: 'success',
state: 'error',
error: 'Template shortid:' + schedule.templateShortid + ' was not found',
finishDate: self.options.now()

@@ -153,0 +169,0 @@ }

/*!
* Copyright(c) 2014 Jan Blaha
* Copyright(c) 2017 Jan Blaha
*

@@ -13,2 +13,3 @@ * Extension capable of planning reoccurring jobs which are printing specified templates into reports.

var JobProcessor = require('./jobProcessor')
var moment = require('moment')

@@ -64,2 +65,13 @@ var Scheduling = function (reporter, definition) {

Scheduling.prototype._updateNextRun = function (entity) {
var cron = new CronTime(entity.cron)
entity.nextRun = cron._getNextDateFrom(new Date()).toDate()
var intervalMS = cron._getNextDateFrom(new Date(entity.nextRun.getTime() + 1000)).toDate().getTime() - entity.nextRun.getTime()
if (intervalMS < this.definition.options.minScheduleInterval) {
throw new Error('Minimal interval for schedule is ' + moment.duration(this.definition.options.minScheduleInterval).humanize() +
'. You are trying to set ' + moment.duration(intervalMS - 10000).humanize())
}
}
Scheduling.prototype._beforeCreateHandler = function (entity) {

@@ -78,4 +90,7 @@ if (!entity.shortid) {

entity.enabled = entity.enabled !== false // default false
var cron = new CronTime(entity.cron)
entity.nextRun = cron._getNextDateFrom(new Date()).toDate()
this._updateNextRun(entity)
if (entity.enabled !== false && !entity.templateShortid) {
throw new Error('Enabled schedules needs to include template')
}
}

@@ -86,11 +101,15 @@

if (entity.name) {
// only update for updates from ui
if (entity.name && entity.state) {
entity.modificationDate = new Date()
}
this._updateNextRun(entity)
entity.state = 'planned'
if (entity.cron) {
entity.modificationDate = new Date()
var cron = new CronTime(entity.cron)
entity.nextRun = cron._getNextDateFrom(new Date()).toDate()
entity.state = 'planned'
if (entity.enabled !== false && !entity.templateShortid) {
throw new Error('Enabled schedules needs to include template')
}
if (!entity.cron) {
throw new Error('cron expression must be set.')
}
}

@@ -133,3 +152,4 @@ }

interval: 5000,
maxParallelJobs: 5
maxParallelJobs: 5,
minScheduleInterval: 60000
}, definition.options)

@@ -136,0 +156,0 @@

{
"name": "jsreport-scheduling",
"version": "1.1.1",
"version": "1.2.0",
"description": "jsreport extension for scheduling background rendering jobs",

@@ -35,2 +35,3 @@ "scripts": {

"in-publish": "2.0.0",
"moment": "2.17.1",
"shortid": "2.2.6",

@@ -37,0 +38,0 @@ "underscore": "1.8.3"

@@ -178,5 +178,3 @@ /******/ (function(modules) { // webpackBootstrap

if (response !== _this.props.entity.nextRun) {
_this.props.onUpdate({ _id: _this.props.entity._id, nextRun: response });
}
_this.setState({ nextRun: response });

@@ -199,7 +197,19 @@ case 5:

}, {
key: 'componentDidUpdate',
value: function componentDidUpdate() {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.updateNextRun.cancel();
}
}, {
key: 'componentDidMount',
value: function componentDidMount() {
this.updateNextRun();
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate(prevProps, prevState) {
if (this.props.entity.cron !== prevProps.entity.cron) {
this.updateNextRun();
}
}
}, {
key: 'openReport',

@@ -406,4 +416,7 @@ value: function () {

var entity = this.props.entity;
var count = this.state.count;
var _state = this.state,
count = _state.count,
nextRun = _state.nextRun;
nextRun = nextRun || entity.nextRun;

@@ -423,3 +436,3 @@ return _react2.default.createElement(

),
entity.nextRun ? _react2.default.createElement(
nextRun ? _react2.default.createElement(
'div',

@@ -435,3 +448,3 @@ null,

null,
entity.nextRun.toLocaleString()
nextRun.toLocaleString()
)

@@ -438,0 +451,0 @@ ) : _react2.default.createElement(

@@ -23,5 +23,3 @@ import React, { Component } from 'react'

const response = await Studio.api.get(`api/scheduling/nextRun/${this.props.entity.cron}`)
if (response !== this.props.entity.nextRun) {
this.props.onUpdate({ _id: this.props.entity._id, nextRun: response })
}
this.setState({ nextRun: response })
}

@@ -39,6 +37,16 @@ }, 500)

componentDidUpdate () {
componentWillUnmount () {
this.updateNextRun.cancel()
}
componentDidMount () {
this.updateNextRun()
}
componentDidUpdate (prevProps, prevState) {
if (this.props.entity.cron !== prevProps.entity.cron) {
this.updateNextRun()
}
}
async openReport (t) {

@@ -126,8 +134,9 @@ if (t.state === 'success') {

const { entity } = this.props
const { count } = this.state
let { count, nextRun } = this.state
nextRun = nextRun || entity.nextRun
return <div className='block custom-editor'>
<div><h1><i className='fa fa-calendar' /> {entity.name}</h1>
{entity.nextRun ? (<div><span>next run&nbsp;&nbsp;</span>
<small>{entity.nextRun.toLocaleString()}</small>
{nextRun ? (<div><span>next run&nbsp;&nbsp;</span>
<small>{nextRun.toLocaleString()}</small>
</div>) : <div>Not planned yet. Fill CRON expression and report template in the properties.</div>}

@@ -134,0 +143,0 @@ </div>

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc