45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
/**
|
|
* @author Martin Karkowski
|
|
* @email m.karkowski@zema.de
|
|
* @create date 2020-02-18 14:06:50
|
|
* @modify date 2020-11-11 13:07:08
|
|
* @desc [description]
|
|
*/
|
|
|
|
import { promisify } from 'util';
|
|
import { finishTask, getActiveTasksFromMES, getTasksFromMES, startTask } from '../src/xetics.functions';
|
|
|
|
const sleep = promisify(setTimeout)
|
|
|
|
const NAME = 'Einlegen'
|
|
|
|
async function main(){
|
|
|
|
const active = await getActiveTasksFromMES(NAME);
|
|
|
|
if (active.length > 0){
|
|
const finished = await finishTask(NAME, active[0].id, 1, [], []);
|
|
console.log(finished ? 'Finished already active Task!' : 'Could not finish active Task');
|
|
} else {
|
|
const res = await getTasksFromMES(NAME);
|
|
if (res.length > 0) {
|
|
// console.log(res[0])
|
|
console.log(NAME, 'Found Task ->', JSON.stringify(res, undefined ,4));
|
|
// Finish the Task.
|
|
const started = await startTask(NAME, res[0].id, 1);
|
|
|
|
console.log(started ? 'Started Task!' : 'Could not start the Task');
|
|
|
|
if (started){
|
|
await sleep(1000)
|
|
const finished = await finishTask(NAME, res[0].id, 1, [], []);
|
|
|
|
console.log(finished ? 'Finished Task!' : 'Could not finish the Task');
|
|
}
|
|
} else {
|
|
console.log('NO Task available.')
|
|
}
|
|
}
|
|
}
|
|
|
|
main().catch(console.error) |