main
HerrHase 8 months ago
parent 95eae7282a
commit f9a221d8cf

@ -24,7 +24,7 @@ class Db {
this.data = {
'slug': this.slug,
'date_created_at': dayjs().toISOString(),
'date_run_at': dayjs().toISOString()
'date_run_started_at': dayjs().toISOString()
}
db.data.runs.push(run)

@ -1,3 +1,5 @@
import State from './_state.ts'
/**
* Docket
*
@ -17,7 +19,9 @@ class Docket {
private data: object
private options: object
private db: object
private states: array
/**
*
*
@ -27,6 +31,7 @@ class Docket {
public constructor(config: object, db: object) {
this.config = config
this.db = db
this.states = []
}
public getData() {
@ -48,6 +53,23 @@ class Docket {
public getDb(): object {
return this.db
}
public addState(value: State) {
this.states.push(value)
}
public hasState(value: State) {
let result = false
for (let index in this.states) {
if (this.states[index] == value) {
result = true
break
}
}
return result
}
}
export default Docket

@ -4,6 +4,7 @@ import Docket from './_docket.ts'
import { resolveActionClass } from './helpers/resolver.ts'
import logger from './helpers/logger.ts'
import State from './_state.ts'
/**
* run through a single config, getting each action with config
@ -18,6 +19,11 @@ async function run(config: object) {
let db = new Db(config.slug)
let docket = new Docket(config, db)
// update db
await db.update({
'date_started_at': dayjs().toISOString()
})
logger(config.slug).info('has started')
@ -46,10 +52,12 @@ async function run(config: object) {
logger(config.slug).info('has finished')
// update db
await db.update({
'date_run_at': dayjs().toISOString()
})
// update db only state FINISHED is set
if (docket.hasState(State.FINISHED)) {
await db.update({
'date_finished_at': dayjs().toISOString()
})
}
return docket
}

@ -0,0 +1,14 @@
/**
*
*
* @author Björn Hase <me@herr-hase.wtf>
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://git.node001.net/HerrHase/super-hog.git
*
*/
enum State {
FINISHED
}
export default State
Loading…
Cancel
Save