0.0.4 • Published 5 years ago

vue-crontab v0.0.4

Weekly downloads
54
License
MIT
Repository
github
Last release
5 years ago

VueCrontab

Periodic processing management system (crontab) running on Vue.js

Introduction

VueCrontab is a plug-in for Vue.js that executes functions according to a specified schedule. The schedule consists of hours, minutes, seconds, days of the week, etc. VueCrontab executes the specified function when it matches the date and time. By using this you can easily implement periodic processing to run in the background.

Install

$ npm install vue-crontab

Examples

Usage

Counter updated every second.

import Vue from 'vue'
import VueCrontab from 'vue-crontab'

Vue.use(VueCrontab)

new Vue({
  el: '#app',
  render: h => h(App)
})
<template>
  <div id="app">
    <div>
      <div class="counter">{{ counter }}</div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      counter: 0
    }
  },
  created () {
    let result = this.$crontab.addJob({
      name: 'counter',
      interval: {
        seconds: '/1',
      },
      job: this.countUp
    })
  },
  methods: {
    countUp () {
      this.counter += 1
    }
  }
}
</script>

Reference

VueCrontab

option

nametypedescriptiondefault
intervalnumberThe interval to check the interval of the managed job.(milliseconds)1000
auto_startBooleanSetting whether to automatically move cron when one or more jobs are reached.true

examples

call setOption before Vue.use() method.

VueCrontab.setOption({
  interval: 100,
  auto_start: false
})

Vue.use(VueCrontab)

methods

nameargumentdescription
addJobArray or Object
enableJobstringEnable job with specified name.
disableJobstringDisable job with specified name.
deleteJobstringDelete job with specified name.
execJobstringManually execute the job with the specified name.
startCrontab-Stop the periodic processing of VueCrontab.
stopCrontab-Start the periodic processing of VueCrontab.
setOptionObjectchange option of VueCrontab.
getOption-get option of VueCrontab.

Job

option

nametypedescription
name (required)Stringjob name.
interval (required)Array or String or ObjectSpecify the periodical execution interval of the job.
job (required)Array or FunctionSpecify the function you want to execute when matching the interval.
syncnumberWhether to synchronize and execute when multiple jobs are registered. 1 = sync, 0 = not sync(default)
conditionArray or FunctionAdd a function when you want to additionally specify job execution conditions in addition to interval. The condition must return Boolean type.

interval

parameters
namerangedefault
milliseconds0 - 9*
seconds0 - 59*
minutes0 - 59*
hours0 - 23*
day1 - 31*
month1 - 12*
year0 -*
week0 - 6 (// Sunday is 0, Monday is 1, and so on.)*
Available symbols
namedescriptionexamples
*All ranges*
/Number divided by 0/2 = every 2 seconds. /5 = every 5 seconds.
-Within the specified numerical range0-10 = between 0 and 10 seconds.
,Used to connect conditions0,1,2 ... 0,10-20,/7 ...
interval examples

execute every 0.1 seconds

{milliseconds: '/1'}

If you want to process with milliseconds, change setOption as well.

VueCrontab.setOption({
  interval: 100
})

execute every minute.

{minutes: '/1'}

execute 0 minutes from 0 to 9 o'clock on the 1st of every month.

{seconds: '0', minutes:'0', hours: '0-9', day: '1'}

1,3,5,10-15 o'clock Monday

{week: '0', seconds: '0', minutes:'0', hours: '1,3,5,10-15'}

job arguments

nametypedescription
exec_dateDateMatch date and time.
last_runDateLast execution date and time.
counternumberNumber of executions.
last_resultanyReturn value of the previous function.
typeString'cron' = executed by periodic processing. 'manual = manually execution.
  methods: {
    countUp ({exec_date, last_run, counter, last_result, type}) {
      return "as the next last_result.";
    }
  }

License

MIT

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago