Skip to content

Commit

Permalink
add(feat): auto start stop jobs and track stat end time
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasHeine committed Nov 28, 2024
1 parent 0a58b23 commit 76ac109
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
11 changes: 5 additions & 6 deletions src/machines/MyControledMachine/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export class Job extends EventEmitter {
state: JobState = JobState.NotAllowedToStart
stateNumber: JobStateNumber = JobStateNumber.NotAllowedToStart
jobOrder: ISA95JobOrderDataType
startTime: Date | undefined = undefined
endTime: Date | undefined = undefined

constructor (jobOrder: ISA95JobOrderDataType) {
super()
Expand Down Expand Up @@ -55,18 +57,13 @@ export class Job extends EventEmitter {
case JobState.AllowedToStart:
this.state = JobState.Running
this.stateNumber = JobStateNumber.Running
this.startTime = new Date()
this.emit("changed", this.jobOrder)
return true
case JobState.NotAllowedToStart:
this.state = JobState.AllowedToStart
this.stateNumber = JobStateNumber.AllowedToStart
this.emit("changed", this.jobOrder)
// TODO check startTime if possible jump into Running!
if (true) {
this.state = JobState.Running
this.stateNumber = JobStateNumber.Running
this.emit("changed", this.jobOrder)
}
return true
default:
return false
Expand All @@ -78,11 +75,13 @@ export class Job extends EventEmitter {
case JobState.Running:
this.state = JobState.Ended
this.stateNumber = JobStateNumber.Ended
this.endTime = new Date()
this.emit("changed", this.jobOrder)
return true
case JobState.Interrupted:
this.state = JobState.Ended
this.stateNumber = JobStateNumber.Ended
this.endTime = new Date()
this.emit("changed", this.jobOrder)
return true
default:
Expand Down
34 changes: 29 additions & 5 deletions src/machines/MyControledMachine/jobcontrol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import {
ReferenceTypeIds,
UAEventType,
coerceNodeId,
coerceLocalizedText
coerceLocalizedText,
coerceDateTime
} from 'node-opcua'
import { ServerRolePermissionGroup } from '../../permissiongroups'
import { ISA95JobOrderDataType } from './interfaces'
Expand Down Expand Up @@ -161,8 +162,8 @@ export const createJobContolLogic = async (addressSpace: AddressSpace): Promise<
ID: `${randomUUID()}`,
Description: "", // TODO!
JobOrderID: JobOrderId,
StartTime: null, // TODO!
EndTime: null, // TODO!
StartTime: coerceDateTime(job!.startTime),
EndTime: coerceDateTime(job!.endTime),
JobState: [], // ISA95StateDataType[]
JobResponseData: [], // ISA95ParameterDataType[]
PersonnelActuals: [], // ISA95PersonnelDataType[]
Expand Down Expand Up @@ -348,6 +349,29 @@ export const createJobContolLogic = async (addressSpace: AddressSpace): Promise<
return Array.from(JobOrderMap.values()).map((job: Job) => { return job.jobOrder })
}

function getJobList(): Job[] {
return Array.from(JobOrderMap.values()).map((job: Job) => { return job })
}

setInterval(() => {
const jobs = getJobList()
jobs.forEach((job) => {

switch (job.state) {
case JobState.AllowedToStart:
job.start()
break;
case JobState.Running:
setTimeout(() => {
job.stop()
}, 10 * 1000)
break;
default:
break;
}
})
}, 1 * 1000)

// JobOrderList
let jobs: ISA95JobOrderDataType[]

Expand Down Expand Up @@ -844,8 +868,8 @@ export const createJobContolLogic = async (addressSpace: AddressSpace): Promise<
ID: `${randomUUID()}`,
Description: "", // TODO!
JobOrderID: JobOrderId,
StartTime: null, // TODO!
EndTime: null, // TODO!
StartTime: coerceDateTime(job!.startTime),
EndTime: coerceDateTime(job!.endTime),
JobState: [
new Variant({
value: [
Expand Down

0 comments on commit 76ac109

Please sign in to comment.