Fixing wamo manager

This commit is contained in:
Martin Karkowski 2021-08-30 12:41:27 +02:00
parent ed6cf73d6f
commit 675b8ceda7
4 changed files with 98 additions and 33 deletions

View File

@ -28,6 +28,7 @@ import {
IMqttSettings,
validFormats
} from "../../mqtt-connector/types/interfaces";
import { JobDTO } from "../../xetics-lean-connector/generated";
import {
IXeticsInterfaceClient,
MESTask
@ -197,6 +198,8 @@ export class WaMOBaseModule
taskFinished: (options: {
checkedInWorkpieceCarrier: string;
productId: number;
numOfOpenJobs: number
}) => Promise<void>;
resetOnInit?: boolean,
autoStart?: boolean,
@ -380,6 +383,8 @@ export class WaMOBaseModule
// present.
if (tasks.length === 0) {
tasks = await _this._xetics.updateTasks();
// Wait until the update arrived here
// await _this._xetics.availableTasks.waitForUpdate();
}
// Only if there are tasks we try to get the product id for
@ -404,12 +409,13 @@ export class WaMOBaseModule
if (productIdToStartWith) {
// We are not running in the demo-mode and we have
// a task to start, which we are able to select.
await _this.performCurrentTask(productIdToStartWith);
const numOfOpenJobs = await _this.performCurrentTask(productIdToStartWith);
// Now we have finished the task.
await settings.taskFinished({
checkedInWorkpieceCarrier: carrierId,
productId: productIdToStartWith
productId: productIdToStartWith,
numOfOpenJobs: numOfOpenJobs as number
});
}
}
@ -754,7 +760,7 @@ export class WaMOBaseModule
@exportMethod({
paramsHasNoCallback: true
})
public async performCurrentTask(productIdToStartWith: number): Promise<void> {
public async performCurrentTask(productIdToStartWith: number): Promise<number | false> {
if (this.connected.getContent()) {
const _this = this;
@ -768,6 +774,10 @@ export class WaMOBaseModule
}
let finished = false;
let taskFinished: false | {
jobsOnStation: JobDTO[];
jobsOfProduct: number;
} = false;
while (!finished) {
finished = true;
@ -804,11 +814,12 @@ export class WaMOBaseModule
// If we have waited to finish a Task, we are able
// to proceed with the task.
if (value.active == false && first == false) {
// Unsubscribe the Observer
clearObservers();
// Unsubscribe the Observer
if (value.result) {
clearObservers();
resolve();
} else if (value.error) {
clearObservers();
reject(new Error("An Error is returned from the Processmodul"));
}
}
@ -872,7 +883,7 @@ export class WaMOBaseModule
_this.connector.forcePublish();
// Mark the Task as Finished inside of the MES
const taskFinished = await _this._xetics.finishCurrentTask();
taskFinished = await _this._xetics.finishCurrentTask();
// Only if the Task has been finished proceed
if (taskFinished) {
@ -885,6 +896,7 @@ export class WaMOBaseModule
// We have set finished = true to end the
// loop
finished = (await this._xetics.getCurrentTask())?.lotId != productIdToStartWith;
finished = taskFinished.jobsOnStation.length === 0;
} else {
_this._logger.error("Failed to finish the Task.");
_this.baseInformation.getContent().logical.currentState = "error";
@ -904,6 +916,8 @@ export class WaMOBaseModule
}
}
const numOfTask = (taskFinished as any).jobsOfProduct as number;
return numOfTask;
}
}

View File

@ -331,10 +331,12 @@ export class WaMOLineManager extends InjectableNopeBaseModule {
taskFinished: async (options: {
checkedInWorkpieceCarrier: string;
productId: number;
numOfOpenJobs: number;
}) => {
// Now we need to test, if the product has open tasks, after we have finished
// that one
if (options.productId && await this._amountOfTasksForProduct(options.productId) === 1) {
_this._logger.info("Task on Station finished. options =", options);
if (options.numOfOpenJobs <= 0) {
await this.carrierMapper.removeProductFromCarrier(options.checkedInWorkpieceCarrier);
}
},

View File

@ -34,7 +34,7 @@ function _cacheFunction<T>(func: (...args) => Promise<T>, id: string) {
cache.get(id).set(argsAsKey, result);
}
return cache.get(id).get(argsAsKey);
return cache.get(id).get(argsAsKey) as T;
};
return exportFunctionToDispatcher(wrapped, {
@ -110,6 +110,12 @@ export const finishTask = exportFunctionToDispatcher(_finishTask, {
*/
export const amountOfTasksForProduct = _cacheFunction(_amountOfTasksForProduct, "amountOfTasksForProduct");
export const getCapabilitiesOfStation = _cacheFunction(_getCapabilitiesOfStation, "getCapabilitiesOfStation");
export const getAllJobs = _cacheFunction(_getAllJobs, "getAllJobs");
export const getNextJobsIfFinished = exportFunctionToDispatcher(_getNextJobsIfFinished, { "id": "getNextJobsIfFinished" });
const _adaptJobs = _cacheFunction(__adaptJobs, "_adaptJobs");
/**
@ -324,6 +330,48 @@ async function _startTask(
return true;
}
async function _getCapabilitiesOfStation(station: number | string) {
const id = await getStationId(station);
const result: {
"id": number,
"processTarget": {
"name": string,
"id": number
}
}[] = (await StationControllerService.getEquipment({ id })).capabilities;
const processIds = result.map(item => item.processTarget.id);
const capabilities = result.map(item => item.processTarget.name);
return {
processIds,
capabilities
};
}
async function _getAllJobs(size = MAX_QUERY_LIST_SIZE) {
return await JobControllerService.getTrackingJobs2({ size });
}
/**
* Function to receive the next Jobs of this entity
*
* @author M.Karkowski
* @param {(number | string)} station
* @param {number} jobId
* @return {*}
*/
async function _getNextJobsIfFinished(station: number | string, jobId: number, size = MAX_QUERY_LIST_SIZE) {
const stationId = await getStationId(station);
const processIds = (await getCapabilitiesOfStation(stationId)).processIds;
const nextJobs: JobDTO[] = await JobControllerService.getNextJob({ jobId });
return {
jobsOnStation: nextJobs.filter(job => processIds.includes(job.processTarget.id)),
jobsOfProduct: nextJobs.length
};
}
/**
* Function to Mark a Task as finished.
* @param station The Station (Name or ID)
@ -342,8 +390,10 @@ async function _finishTask(
const stationId = await getStationId(station);
// Get the Active Jobs for the Equipment
const job = await JobControllerService.stopSingleTracking({
const nextJobs = await getNextJobsIfFinished(stationId, jobId);
// Finish the next job
await JobControllerService.stopSingleTracking({
requestBody: {
jobId,
qualityParameters,
@ -358,10 +408,11 @@ async function _finishTask(
resetCache([
"getTasksFromMES",
"getActiveTasksFromMES",
"amountOfTasksForProduct"
"amountOfTasksForProduct",
"getAllJobs"
]);
return true;
return nextJobs;
}
/**
@ -371,10 +422,7 @@ async function _finishTask(
* @param {(string | number)} product
* @return {*}
*/
async function _amountOfTasksForProduct(product: string | number,) {
const jobs = await JobControllerService.getTrackingJobs2({
size: MAX_QUERY_LIST_SIZE
});
async function _amountOfTasksForProduct(product: string | number, size = MAX_QUERY_LIST_SIZE) {
const jobs = await getAllJobs(size);
return jobs.filter(job => job.lotId == product).length > 0;
}

View File

@ -75,7 +75,10 @@ export interface IXeticsInterfaceClient {
finishCurrentTask(
qualityParameters?: QualityParameterDTO[],
traceabilityParameters?: TraceabilityParameterDTO[]
): Promise<boolean>;
): Promise<false | {
jobsOnStation: JobDTO[];
jobsOfProduct: number;
}>;
/**
* Start the current Task.
@ -230,6 +233,7 @@ export class XeticsInterfaceClient
this.availableTasks.setContent(
await getTasksFromMES(this._station)
);
this._logger.info("Updated tasks, because we wont find a matching solution");
_possibleTasks = this.availableTasks
.getContent()
.filter((task) => task.lotId === id || task.lotAutoId === id);
@ -305,7 +309,9 @@ export class XeticsInterfaceClient
// If the task has been sucessfully finished => assign a new Task.
if (finished) {
await this.updateTasks();
// We dont need to check for open task. It is only one Task currently
// active. Multiple Tasks can be active at a time.
await this.updateTasks([]);
}
// Return the Result.
@ -325,20 +331,18 @@ export class XeticsInterfaceClient
@exportMethod({
paramsHasNoCallback: true
})
async updateTasks() {
async updateTasks(activeTasks = null) {
let _taskActive = false;
console.time(this.identifier + "-getActiveTasksFromMES");
// Check if there exists a currently active Task
// if so => assign this task
const activeTasks = await getActiveTasksFromMES(
this._station
);
console.timeEnd(this.identifier + "-getActiveTasksFromMES");
if (activeTasks == null) {
// Check if there exists a currently active Task
// if so => assign this task
activeTasks = await getActiveTasksFromMES(
this._station
);
}
if (activeTasks.length > 0) {
@ -372,9 +376,6 @@ export class XeticsInterfaceClient
this.taskActive.setContent(_taskActive);
// Return the whether a task has been assigned.
return (
this.currentTask.getContent() !== undefined ||
this.currentTask.getContent() !== null
);
return this.availableTasks.getContent();
}
}