Refactor scrobble and sql retry code