Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logperf5 #4030

Open
wants to merge 22 commits into
base: master-qa
Choose a base branch
from
Open

Logperf5 #4030

wants to merge 22 commits into from

Conversation

ClaudeROSSI
Copy link
Contributor

No description provided.

Comment on lines 17 to 52
export class OcppPendingCommand {
private command;
private resolveCallback: FctOCPPResponse;
private rejectCallback: FctOCPPReject;
private timer: NodeJS.Timeout;

public constructor(command: string, resolveCallback: FctOCPPResponse, rejectCallback: FctOCPPReject, timer: NodeJS.Timeout) {
this.command = command;
this.resolveCallback = resolveCallback;
this.rejectCallback = rejectCallback;
this.timer = timer;
}

public getCommand(): string {
return this.command;
}

public resolve(payload: Record<string, unknown> | string): void {
this.clearTimer();
this.resolveCallback(payload);
}

public reject(error: OCPPError): void {
this.clearTimer();
this.rejectCallback(error);
}

private clearTimer() {
const timer = this.timer;
if (timer) {
this.timer = null;
clearTimeout(timer);
}
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmargaron , @Ramzay : Here is the main change that I'm trying to introduce to improve the code maintainability! ;)

The class OcppPendingCommand replaces the former ocppRequest type!

Comment on lines +242 to +250
private consumePendingOcppCommands(messageID: string) {
const pendingOcppCommand = this.pendingOcppCommands[messageID];
if (pendingOcppCommand) {
// It can be consumed only once - so we remove it from the cache
delete this.pendingOcppCommands[messageID];
}
return pendingOcppCommand;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remove the pending command from the cache as soon as we use it!

Comment on lines +101 to +103
public async sendMessageAndWaitForResult(messageID: string, command: Command, data: Record<string, any>): Promise<unknown> {
// Create a pending promise
const pendingPromise = new Promise((resolve, reject) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ramzay , @lmargaron : I couln't get rid of the new Promise()!

But now the logic is isolated in a dedicated method which only handles message of type: OCPPMessageType.CALL_MESSAGE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant