Robospice retry policy custom implementation

2019-09-09 02:49发布

问题:

I need to implement such behaviour. Something like polling remote web server for the some period of time, checking for the condition in response from the server, for example variable condition.
To be more specific, consider an example. I need to poll server every 5 secodns during 5 minutes and than fail. There is great feature in Robospice library - RetryPolicy, nearly what I need.
I has getRetryCount, getDelayBeforeRetry methods. Exactly what I need to implement my task.
But I need to perform retries when result code is HTTP::OK. So in this case I have to make delays inside my activities, and send new request from there, it would be better to separate this logic inside some other class and in the service.
So I need some middleware to handle responses from the server.
I don't Robospice library perfectly so maybe there is already any way to do this.
Please suggest the best way to do this, thank you.

回答1:

You can probably achieve that by using the OkHttp extension of RoboSpice. Check out this example for response analysis at a lower level.