Skip to content

Commit

Permalink
Cancel ongoing RFC call
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrdjan committed Jun 14, 2021
1 parent a94cf49 commit 5503a61
Show file tree
Hide file tree
Showing 24 changed files with 526 additions and 39 deletions.
26 changes: 26 additions & 0 deletions doc/api.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
- **[addon](#addon)**
- [setIniFileDirectory](#setinifiledirectory)
- [loadCryptoLibrary](#loadcryptolibrary)
- [cancelClient](#cancelclient)
- **[Client](#client)**
- [Properties](#client-properties)
- [Constructor](#client-constructor)
Expand Down Expand Up @@ -35,6 +37,14 @@ Usage: [usage/addon](usage.md#addon)
loadCryptoLibrary(cryptoLibraryPath: string)
```

### cancelClient

Usage: [usage/addon](usage.md#addon)

```ts
cancelClient(client: Client, callback?: Function): void | Promise<any>;
```

## Client

Usage: [usage/client](usage.md#client)
Expand Down Expand Up @@ -125,6 +135,14 @@ Close connection (direct client only):
close(callback?: Function): void | Promise<void>
```

#### cancel

Cancel connection:

```ts
cancel(callback?: Function): void | Promise<any>
```

#### ping

RFC ping the ABAP backend system, returning:
Expand Down Expand Up @@ -260,6 +278,14 @@ acquire([client1], callback?:Function) // Release 1 client
acquire([client1, client2], callback?:Function) // Release Array of 2 clients
```
#### cancel
Cancel connection:
```ts
cancel(client, callback?: Function): void | Promise<any>
```
#### ready
Check if the number of ready connections is below the pool `ready_low` and open new connections if needed.
Expand Down
75 changes: 75 additions & 0 deletions doc/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
- **[Connection Pool](#connection-pool)**
- [Pool Options](#pool-options)
- **[Closing connections](#closing-connections)**
- **[Cancel connection](#cancel-connection)**


<a name="server-toc"></a>

Expand Down Expand Up @@ -532,6 +534,79 @@ is managed, the pool leased connections set is updated.
| group | COMMUNICATION_FAILURE | Problems with the network connection (or backend broke down and killed the connection) |
| group | EXTERNAL_RUNTIME_FAILURE | Problems in the RFC runtime of the external program (i.e "this" library) |

## Cancel connection

Client or pool can cancel the ongoing RFC call, when running too long for example. The `cancel()` method, exposed at addon, client and pool level, will abort the RFC call and close the connection.

Function call:

```node
const client = await pool.acquire();

try {
const result = await client
.call("RFC_PING_AND_WAIT", {
SECONDS: N,
})
} catch (err) {
// raised when cancellation called:
// {
// name: 'RfcLibError',
// group: 4,
// code: 7,
// codeString: 'RFC_CANCELED',
// key: 'RFC_CANCELED',
// message: 'Connection was canceled.'
// }
}
```

Cancellation:

```node
await client.cancel();
await pool.cancel(client);
await addon.cancelClient(client);
```

Example:

```node
// call function that takes 5 sec to complete
client
.call("RFC_PING_AND_WAIT", {
SECONDS: 5,
})
.then((res) => {
console.log("function result", res);
})
.catch((err) => {
console.error(err);
// function error {
// name: 'RfcLibError',
// group: 4,
// code: 7,
// codeString: 'RFC_CANCELED',
// key: 'RFC_CANCELED',
// message: 'Connection was canceled.'
// }
});

// terminate afer 1 sec
setTimeout(() => {
client
.cancel()
.then((res) => {
console.log(res);
// { connectionHandle: 140329751824896, result: 'cancelled' }
})
.catch((err) => {
console.error("cancellation error", err);
});
}, 1000);

```

<a name="server"></a>

## Server (experimental)
Expand Down
11 changes: 7 additions & 4 deletions lib/wrapper/noderfc-bindings.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="node" />
declare const Promise: any;
import { RfcClientBinding } from "./sapnwrfc-client";
import { RfcClientBinding, Client } from "./sapnwrfc-client";
import { RfcPoolBinding } from "./sapnwrfc-pool";
import { RfcThroughputBinding } from "./sapnwrfc-throughput";
import { RfcServerBinding } from "./sapnwrfc-server";
Expand Down Expand Up @@ -28,6 +28,10 @@ export interface NWRfcBinding {
environment: NodeRfcEnvironment;
setIniFileDirectory(iniFileDirectory: string): any | undefined;
loadCryptoLibrary(libAbsolutePath: string): any | undefined;
cancel(client: {
connectionHandle: number;
functionHandle?: number;
}, callback?: Function): any | undefined;
verbose(): this;
}
declare let noderfc_binding: NWRfcBinding;
Expand All @@ -45,6 +49,5 @@ declare const environment: {
} & {
noderfc: NodeRfcBindingVersions;
};
export { Promise };
export { noderfc_binding };
export { environment };
declare function cancelClient(client: Client, callback?: Function): void | Promise<any>;
export { Promise, noderfc_binding, environment, cancelClient };
33 changes: 32 additions & 1 deletion lib/wrapper/noderfc-bindings.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/wrapper/noderfc-bindings.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/wrapper/noderfc-cancel.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
13 changes: 13 additions & 0 deletions lib/wrapper/noderfc-cancel.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/wrapper/noderfc-cancel.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/wrapper/sapnwrfc-client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export declare class Client {
open(callback?: Function): void | Promise<Client>;
ping(callback?: Function): void | Promise<boolean>;
close(callback?: Function): void | Promise<void>;
cancel(callback?: Function): void | Promise<any>;
resetServerContext(callback?: Function): void | Promise<void>;
release(callback?: Function): void | Promise<void>;
call(rfmName: string, rfmParams: RfcObject, callOptions?: RfcClientOptions): Promise<RfcObject>;
Expand Down
9 changes: 9 additions & 0 deletions lib/wrapper/sapnwrfc-client.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5503a61

Please sign in to comment.