Fixing wamo manager
This commit is contained in:
parent
ed6cf73d6f
commit
675b8ceda7
@ -28,6 +28,7 @@ import {
|
|||||||
IMqttSettings,
|
IMqttSettings,
|
||||||
validFormats
|
validFormats
|
||||||
} from "../../mqtt-connector/types/interfaces";
|
} from "../../mqtt-connector/types/interfaces";
|
||||||
|
import { JobDTO } from "../../xetics-lean-connector/generated";
|
||||||
import {
|
import {
|
||||||
IXeticsInterfaceClient,
|
IXeticsInterfaceClient,
|
||||||
MESTask
|
MESTask
|
||||||
@ -197,6 +198,8 @@ export class WaMOBaseModule
|
|||||||
taskFinished: (options: {
|
taskFinished: (options: {
|
||||||
checkedInWorkpieceCarrier: string;
|
checkedInWorkpieceCarrier: string;
|
||||||
productId: number;
|
productId: number;
|
||||||
|
numOfOpenJobs: number
|
||||||
|
|
||||||
}) => Promise<void>;
|
}) => Promise<void>;
|
||||||
resetOnInit?: boolean,
|
resetOnInit?: boolean,
|
||||||
autoStart?: boolean,
|
autoStart?: boolean,
|
||||||
@ -380,6 +383,8 @@ export class WaMOBaseModule
|
|||||||
// present.
|
// present.
|
||||||
if (tasks.length === 0) {
|
if (tasks.length === 0) {
|
||||||
tasks = await _this._xetics.updateTasks();
|
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
|
// Only if there are tasks we try to get the product id for
|
||||||
@ -404,12 +409,13 @@ export class WaMOBaseModule
|
|||||||
if (productIdToStartWith) {
|
if (productIdToStartWith) {
|
||||||
// We are not running in the demo-mode and we have
|
// We are not running in the demo-mode and we have
|
||||||
// a task to start, which we are able to select.
|
// 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.
|
// Now we have finished the task.
|
||||||
await settings.taskFinished({
|
await settings.taskFinished({
|
||||||
checkedInWorkpieceCarrier: carrierId,
|
checkedInWorkpieceCarrier: carrierId,
|
||||||
productId: productIdToStartWith
|
productId: productIdToStartWith,
|
||||||
|
numOfOpenJobs: numOfOpenJobs as number
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -754,7 +760,7 @@ export class WaMOBaseModule
|
|||||||
@exportMethod({
|
@exportMethod({
|
||||||
paramsHasNoCallback: true
|
paramsHasNoCallback: true
|
||||||
})
|
})
|
||||||
public async performCurrentTask(productIdToStartWith: number): Promise<void> {
|
public async performCurrentTask(productIdToStartWith: number): Promise<number | false> {
|
||||||
if (this.connected.getContent()) {
|
if (this.connected.getContent()) {
|
||||||
const _this = this;
|
const _this = this;
|
||||||
|
|
||||||
@ -768,6 +774,10 @@ export class WaMOBaseModule
|
|||||||
}
|
}
|
||||||
|
|
||||||
let finished = false;
|
let finished = false;
|
||||||
|
let taskFinished: false | {
|
||||||
|
jobsOnStation: JobDTO[];
|
||||||
|
jobsOfProduct: number;
|
||||||
|
} = false;
|
||||||
|
|
||||||
while (!finished) {
|
while (!finished) {
|
||||||
finished = true;
|
finished = true;
|
||||||
@ -805,10 +815,11 @@ export class WaMOBaseModule
|
|||||||
// to proceed with the task.
|
// to proceed with the task.
|
||||||
if (value.active == false && first == false) {
|
if (value.active == false && first == false) {
|
||||||
// Unsubscribe the Observer
|
// Unsubscribe the Observer
|
||||||
clearObservers();
|
|
||||||
if (value.result) {
|
if (value.result) {
|
||||||
|
clearObservers();
|
||||||
resolve();
|
resolve();
|
||||||
} else if (value.error) {
|
} else if (value.error) {
|
||||||
|
clearObservers();
|
||||||
reject(new Error("An Error is returned from the Processmodul"));
|
reject(new Error("An Error is returned from the Processmodul"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -872,7 +883,7 @@ export class WaMOBaseModule
|
|||||||
_this.connector.forcePublish();
|
_this.connector.forcePublish();
|
||||||
|
|
||||||
// Mark the Task as Finished inside of the MES
|
// 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
|
// Only if the Task has been finished proceed
|
||||||
if (taskFinished) {
|
if (taskFinished) {
|
||||||
@ -885,6 +896,7 @@ export class WaMOBaseModule
|
|||||||
// We have set finished = true to end the
|
// We have set finished = true to end the
|
||||||
// loop
|
// loop
|
||||||
finished = (await this._xetics.getCurrentTask())?.lotId != productIdToStartWith;
|
finished = (await this._xetics.getCurrentTask())?.lotId != productIdToStartWith;
|
||||||
|
finished = taskFinished.jobsOnStation.length === 0;
|
||||||
} else {
|
} else {
|
||||||
_this._logger.error("Failed to finish the Task.");
|
_this._logger.error("Failed to finish the Task.");
|
||||||
_this.baseInformation.getContent().logical.currentState = "error";
|
_this.baseInformation.getContent().logical.currentState = "error";
|
||||||
@ -904,6 +916,8 @@ export class WaMOBaseModule
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const numOfTask = (taskFinished as any).jobsOfProduct as number;
|
||||||
|
return numOfTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,10 +331,12 @@ export class WaMOLineManager extends InjectableNopeBaseModule {
|
|||||||
taskFinished: async (options: {
|
taskFinished: async (options: {
|
||||||
checkedInWorkpieceCarrier: string;
|
checkedInWorkpieceCarrier: string;
|
||||||
productId: number;
|
productId: number;
|
||||||
|
numOfOpenJobs: number;
|
||||||
}) => {
|
}) => {
|
||||||
// Now we need to test, if the product has open tasks, after we have finished
|
// Now we need to test, if the product has open tasks, after we have finished
|
||||||
// that one
|
// 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);
|
await this.carrierMapper.removeProductFromCarrier(options.checkedInWorkpieceCarrier);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -34,7 +34,7 @@ function _cacheFunction<T>(func: (...args) => Promise<T>, id: string) {
|
|||||||
cache.get(id).set(argsAsKey, result);
|
cache.get(id).set(argsAsKey, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cache.get(id).get(argsAsKey);
|
return cache.get(id).get(argsAsKey) as T;
|
||||||
};
|
};
|
||||||
|
|
||||||
return exportFunctionToDispatcher(wrapped, {
|
return exportFunctionToDispatcher(wrapped, {
|
||||||
@ -110,6 +110,12 @@ export const finishTask = exportFunctionToDispatcher(_finishTask, {
|
|||||||
*/
|
*/
|
||||||
export const amountOfTasksForProduct = _cacheFunction(_amountOfTasksForProduct, "amountOfTasksForProduct");
|
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");
|
const _adaptJobs = _cacheFunction(__adaptJobs, "_adaptJobs");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -324,6 +330,48 @@ async function _startTask(
|
|||||||
return true;
|
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.
|
* Function to Mark a Task as finished.
|
||||||
* @param station The Station (Name or ID)
|
* @param station The Station (Name or ID)
|
||||||
@ -342,8 +390,10 @@ async function _finishTask(
|
|||||||
|
|
||||||
const stationId = await getStationId(station);
|
const stationId = await getStationId(station);
|
||||||
|
|
||||||
// Get the Active Jobs for the Equipment
|
const nextJobs = await getNextJobsIfFinished(stationId, jobId);
|
||||||
const job = await JobControllerService.stopSingleTracking({
|
|
||||||
|
// Finish the next job
|
||||||
|
await JobControllerService.stopSingleTracking({
|
||||||
requestBody: {
|
requestBody: {
|
||||||
jobId,
|
jobId,
|
||||||
qualityParameters,
|
qualityParameters,
|
||||||
@ -358,10 +408,11 @@ async function _finishTask(
|
|||||||
resetCache([
|
resetCache([
|
||||||
"getTasksFromMES",
|
"getTasksFromMES",
|
||||||
"getActiveTasksFromMES",
|
"getActiveTasksFromMES",
|
||||||
"amountOfTasksForProduct"
|
"amountOfTasksForProduct",
|
||||||
|
"getAllJobs"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return true;
|
return nextJobs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -371,10 +422,7 @@ async function _finishTask(
|
|||||||
* @param {(string | number)} product
|
* @param {(string | number)} product
|
||||||
* @return {*}
|
* @return {*}
|
||||||
*/
|
*/
|
||||||
async function _amountOfTasksForProduct(product: string | number,) {
|
async function _amountOfTasksForProduct(product: string | number, size = MAX_QUERY_LIST_SIZE) {
|
||||||
const jobs = await JobControllerService.getTrackingJobs2({
|
const jobs = await getAllJobs(size);
|
||||||
size: MAX_QUERY_LIST_SIZE
|
|
||||||
});
|
|
||||||
|
|
||||||
return jobs.filter(job => job.lotId == product).length > 0;
|
return jobs.filter(job => job.lotId == product).length > 0;
|
||||||
}
|
}
|
@ -75,7 +75,10 @@ export interface IXeticsInterfaceClient {
|
|||||||
finishCurrentTask(
|
finishCurrentTask(
|
||||||
qualityParameters?: QualityParameterDTO[],
|
qualityParameters?: QualityParameterDTO[],
|
||||||
traceabilityParameters?: TraceabilityParameterDTO[]
|
traceabilityParameters?: TraceabilityParameterDTO[]
|
||||||
): Promise<boolean>;
|
): Promise<false | {
|
||||||
|
jobsOnStation: JobDTO[];
|
||||||
|
jobsOfProduct: number;
|
||||||
|
}>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the current Task.
|
* Start the current Task.
|
||||||
@ -230,6 +233,7 @@ export class XeticsInterfaceClient
|
|||||||
this.availableTasks.setContent(
|
this.availableTasks.setContent(
|
||||||
await getTasksFromMES(this._station)
|
await getTasksFromMES(this._station)
|
||||||
);
|
);
|
||||||
|
this._logger.info("Updated tasks, because we wont find a matching solution");
|
||||||
_possibleTasks = this.availableTasks
|
_possibleTasks = this.availableTasks
|
||||||
.getContent()
|
.getContent()
|
||||||
.filter((task) => task.lotId === id || task.lotAutoId === id);
|
.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 the task has been sucessfully finished => assign a new Task.
|
||||||
if (finished) {
|
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.
|
// Return the Result.
|
||||||
@ -325,20 +331,18 @@ export class XeticsInterfaceClient
|
|||||||
@exportMethod({
|
@exportMethod({
|
||||||
paramsHasNoCallback: true
|
paramsHasNoCallback: true
|
||||||
})
|
})
|
||||||
async updateTasks() {
|
async updateTasks(activeTasks = null) {
|
||||||
|
|
||||||
|
|
||||||
let _taskActive = false;
|
let _taskActive = false;
|
||||||
|
|
||||||
console.time(this.identifier + "-getActiveTasksFromMES");
|
if (activeTasks == null) {
|
||||||
|
// Check if there exists a currently active Task
|
||||||
// Check if there exists a currently active Task
|
// if so => assign this task
|
||||||
// if so => assign this task
|
activeTasks = await getActiveTasksFromMES(
|
||||||
const activeTasks = await getActiveTasksFromMES(
|
this._station
|
||||||
this._station
|
);
|
||||||
);
|
}
|
||||||
|
|
||||||
console.timeEnd(this.identifier + "-getActiveTasksFromMES");
|
|
||||||
|
|
||||||
|
|
||||||
if (activeTasks.length > 0) {
|
if (activeTasks.length > 0) {
|
||||||
@ -372,9 +376,6 @@ export class XeticsInterfaceClient
|
|||||||
this.taskActive.setContent(_taskActive);
|
this.taskActive.setContent(_taskActive);
|
||||||
|
|
||||||
// Return the whether a task has been assigned.
|
// Return the whether a task has been assigned.
|
||||||
return (
|
return this.availableTasks.getContent();
|
||||||
this.currentTask.getContent() !== undefined ||
|
|
||||||
this.currentTask.getContent() !== null
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user