Muzei plugin getting stuck in state where it will never get an onUpdate() call
Question
I've written a Muzei plugin that uses the Flickr API to check for and fetch a remote image once an hour. I've noticed that sometimes my app will get in to a bad state however and will stop updating. I've checked the shared prefs (where Muzei stores the next update time) and I've noticed that the scheduled_update_time_millis
variable is no longer present in my art source xml file.
I've double checked my RemoteMuzeiArtSource.onTryUpdate()
method call and I've verified that it should always either call
long CHECK_INTERVAL_MILLIS = 1 * 60 * 60 * 1000L; // 1 hr
scheduleUpdate(System.currentTimeMillis() + CHECK_INTERVAL_MILLIS);
or throw a RetryException
I'm unable to consistently repro getting into this bad state unfortunately, so I'm not sure how it happens.
Full source for my RemoteMuzeiArtSource class lives here: CactusArtSource
Solution
Answering my own question: turns out that any RuntimeException
thrown during execution of onTryUpdate
or onUpdate
will result unsurprisingly in not getting through the entire method and thus (in my case) not scheduling a new update. In my case, it was a RetrofitError being thrown during a bad network event. I threw a little try-catch handling at it and seems to have fixed the error