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

Handling API limit #344

Closed
viktorsebok opened this issue Feb 8, 2023 · 5 comments
Closed

Handling API limit #344

viktorsebok opened this issue Feb 8, 2023 · 5 comments
Assignees
Labels
wontfix This will not be worked on

Comments

@viktorsebok
Copy link

All Mindsphere API call (e.g. Mindconnect API) can answer with an error "API rate limit exceeded"...
This special error also gives an info about a relative time (Retry-After) which indicates that how long in 'seconds' have to wait before making a new request.

My opinion is that, the mindconnect-nodejs should handle this error, and automatically resend the requested message when the defined time is elapsed.
Probably the best place is all implementation of TokenRotation.HttpAction interface function:

@sn0wcat
Copy link
Member

sn0wcat commented Feb 8, 2023

The library provides the

export const retry = async (n: number, func: Function, timoutinMilliseconds: number = 300, logFunction?: Function) 

which can be used to repeat the calls. Now that mindsphere provided retry-after (which is a relatively new feature) , maybe we can add a new function which can wrap such calls and use the retry-after suggestion, instead of preconfigured timeout.

I don't want to have implicit error handling for whole framework, because the API behavior has sometimes subtle differences from API to API - but a better retry method would be worth looking at.

@sn0wcat
Copy link
Member

sn0wcat commented Feb 8, 2023

Example for using the retry function:

 const assetMgmt = sdk.GetAssetManagementClient();
 const asset = (await retry(options.retry, () =>
   assetMgmt.GetAsset(options.assetid)
)) as AssetManagementModels.AssetResourceWithHierarchyPath;

@viktorsebok
Copy link
Author

Sounds promising, but you should consider some special SDK functions, e.g.:

public async PutDataMappings(mappings: Mapping[]): Promise<boolean> {

In case of MindConnectAgent.PutDataMapping, the number of API calls is depending on the input argument.
For instance the input argument has 100 elements, which causes 100 API calls, but the API exceed the limit at 50th element.
We can't handle this situation outside of the SDK function with a "retry" mechanism.

@sn0wcat
Copy link
Member

sn0wcat commented Feb 9, 2023

I never understood why there is no bulk method for creation of data mappings.

@sn0wcat sn0wcat self-assigned this Feb 10, 2023
@stale
Copy link

stale bot commented Jun 18, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Jun 18, 2023
@sn0wcat sn0wcat closed this as completed May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants