View Source PorscheConnEx.Client.PendingRequest (porsche_conn_ex v0.1.0)
Return value from API calls that may take a long time to complete.
Some PorscheConnEx.Client
calls will return {:ok, %PendingRequest{...}}
to indicate that their request has been accepted but not necessarily
completed yet. To determine the eventual fate of the request, see below.
For write requests
Once a write request has been submitted, no further action is required on the part of the library user — if possible, the requested action will be send and performed on the vehicle. However, if the vehicle cannot be reached within a certain amount of time, the call will ultimately fail, and nothing will happen.
To discover the fate of your request, you can use one of two approaches:
- call
PorscheConnEx.Client.poll/2
repeatedly to check the status of the request, waiting for a status other than:in_progress
- call
PorscheConnEx.Client.wait/3
to do the above for you, polling repeatedly until it receives a status other than:in_progress
Note that, in some cases, you may not care about what happens to the
request. For example, if your code is periodically checking
PorscheConnEx.Client.emobility/3
and updating timers and/or charging profiles
based on that data, then it may be fine to just "fire and forget" requests,
since any failures will presumably be noticed and retried on the next check.
For read requests
There is currently only one read request that uses pending requests —
PorscheConnEx.Client.current_overview/2
. Obviously, it would not make
sense to just leave this request pending, since the whole point is to
retrieve the most recent vehicle overview data.
Read requests differ from write requests in that, once the request has succeeded, there is an extra call required to retrieve the final output data. As such, there are two possible approaches:
- call
PorscheConnEx.Client.poll/2
repeatedly to check the status of the request until you get a status other than:in_progress
, then runPorscheConnEx.Client.complete/2
to retrieve the final results (but only if the status is:success
) - call
PorscheConnEx.Client.wait/3
to do all of the above for you — i.e. polling repeatedly until it receives a status other than:in_progress
, then retrieving the final results for you (if status is:success
)
Note that PorscheConnEx.Client.complete/2
will not prevent you from
trying to retrieve the final results of a failed or still-in-progress
request, but the results will almost certainly fail to parse due to missing
data. Wait for a poll result of :success
first.