Skip to content

Conversation

@Shiranuit
Copy link
Contributor

What does this PR do ?

This PR adds a default timeout to every request and a new option timeout to the method query and the actions of the following controllers:

  • Auth (except for login & logout)
  • Document
  • Collection
  • Index
  • Realtime
  • Bulk

This new option can be used to set a timeout (in ms) to every request sent, after the timeout if the request has not been resolved yet the promise will be rejected with a message saying that the request has timed out.

It's also possible to configure a global requestTimeout in the kuzzle constructor.

If the timeout is set to -1 the promise will never be reject and will be waited indefinitely.

Boyscout

Reformatting of tables in markdown files

@Shiranuit Shiranuit linked an issue Apr 22, 2021 that may be closed by this pull request
@Shiranuit Shiranuit changed the title Feature/597 request timeout Add a timeout option for every requests Apr 22, 2021
@codecov
Copy link

codecov bot commented Apr 22, 2021

Codecov Report

Merging #632 (ea885ed) into 7-dev (1e9bdf1) will decrease coverage by 0.18%.
The diff coverage is 30.37%.

Impacted file tree graph

@@            Coverage Diff             @@
##            7-dev     #632      +/-   ##
==========================================
- Coverage   86.18%   86.00%   -0.19%     
==========================================
  Files          34       35       +1     
  Lines        1593     1615      +22     
  Branches      280      294      +14     
==========================================
+ Hits         1373     1389      +16     
- Misses        162      166       +4     
- Partials       58       60       +2     
Impacted Files Coverage Δ
src/controllers/Bulk.ts 70.58% <0.00%> (ø)
src/controllers/Document.ts 68.47% <0.00%> (ø)
src/controllers/Index.ts 75.00% <0.00%> (ø)
src/controllers/Auth.ts 76.59% <11.11%> (-1.67%) ⬇️
src/controllers/Collection.ts 75.86% <23.07%> (+0.42%) ⬆️
src/controllers/Realtime.ts 90.47% <33.33%> (ø)
src/Kuzzle.ts 82.91% <77.77%> (-0.55%) ⬇️
src/RequestTimeoutError.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1e9bdf1...ea885ed. Read the comment docs.

| Property | Type<br/>(default) | Description |
| ---------- | ------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| `queuable` | <pre>boolean</pre><br/>(`true`) | If true, queues the request during downtime, until connected to Kuzzle again |
| `timeout` | <pre>number</pre> | Time (in ms) during which a request will still be waited to be resolved. Set it `-1` if you want to wait indefinitely |
Copy link
Contributor

@Leodau Leodau Apr 23, 2021

Choose a reason for hiding this comment

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

So at this action, the timeout has no default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a default timeout but IDK how to explain that the default timeout is the global timeout configured in the Kuzzle constructor if it has been configured or -1 otherwise, meaning that there is no timeout

Comment on lines +142 to +143
refresh?: 'wait_for',
timeout?: number
Copy link
Contributor

Choose a reason for hiding this comment

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

In the future we should take a look at how to handle these 'shared' options for all queries, having 'refresh' and now 'timeout' could just be the beginning of having tons of query oriented options for every API action.

Copy link
Contributor Author

@Shiranuit Shiranuit May 3, 2021

Choose a reason for hiding this comment

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

You're right, it might be a good thing to have a better way of handling this kind of shared params, this might need a Workshop

@xbill82 xbill82 changed the title Add a timeout option for every requests Add a timeout option for every request May 3, 2021
@Shiranuit Shiranuit merged commit 2e1a76d into 7-dev May 27, 2021
@Shiranuit Shiranuit deleted the feature/597-request-timeout branch May 27, 2021 11:33
@Shiranuit Shiranuit mentioned this pull request May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a timeout to requests

5 participants