glance
glance copied to clipboard
add wait-last-request for custom-api
For https://github.com/glanceapp/glance/issues/568
Config example:
- type: custom-api
url: https:${WEBSERVER_URL}/data # Replaces the value of the key timestamp inside file data.json with the current timestamp
method: post # Notice post
skip-timeout-error: true # Example in the sub2, this should skip timeout error whenever it reaches it as the data from this request isn't needed
subrequests:
sub1:
url: https:${WEBSERVER_URL}/data # A get request the fetches a file data.json that has a timestamp key
wait-last-request: true # The feature added, this waits for the previous request
sub2:
url: https:${WEBSERVER_URL}/slow # Just a request that finishes up after 10s to simulate timeout
skip-timeout-error: true # Just an example
cache: 1s
template: |
<div><pre>POST: {{ (.Subrequest "sub1").JSON.String "timestamp" }}</pre></div>
<div><pre>GET: {{ .JSON.String "timestamp" }}</pre></div>
<div><pre>Matched?: {{ eq (.JSON.String "timestamp") ((.Subrequest "sub1").JSON.String "timestamp") }}</pre></div>
<div><pre>SUB2: {{ (.Subrequest "sub2").Response.Status }}</pre></div>
Output:
POST: 1744133075172
GET: 1744133075172
Matched?: true
SUB2: Get "https://<redacted>/slow": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Setting wait-last-request: false or not setting it at all would make the Matched?: value randomized (GET would get the previous data before the POST happened or GET the latest POST data) since requests are concurrent and would it be unpredictable.
[!CAUTION]
Multiple SUCCESSIVE usage of this property in the same widget can slow your page load time depending on the API's response by another 1~5 seconds (timeout limit) each
wait-last-request.
Hi @svilenmarkov are there any plans to merge this PR in the near future? Thanks
@anant-j I'll add something that would allow you to achieve the same result in a more imperative way in v0.8.
Released: https://github.com/glanceapp/glance/releases/tag/v0.8.0