I'm refactoring some code that would call a web service with a formatted date parameter ("2016-3-10" for example), and if that returned null, would fire off another method with a date one day earlier (like "2016-3-9"). This would happen for at least 3 retries.
I'm refactoring this into RxJava and am not sure how to implement the backoff strategy or which .retry()
or .retryWhen()
operator to use in this situation.
I have the web service returning the usual Observable
using Retrofit.
This is what I have currently:
PictureService pictureService = retrofit.create(PictureService.class);
pictureService.getPhotos(date)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.retry() //Some retry
...
.subscribe()
So which operator would be best used here for retrying the requests, and how should I pass in a new date to the getPhotos()
request when the current date returns null?
Just for the sake of completion here is the Retrofit service that was mentioned above:
@GET("/someurl/photos?api_key=xxxxxxx")
Observable<PictureAPI> getPhotos(@Query("earth_date") String earthDate);