-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle retry for redis io flow (#274)
- Loading branch information
1 parent
3d44ad7
commit 8a0f53b
Showing
6 changed files
with
265 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package feast.retry; | ||
|
||
import org.apache.beam.sdk.util.BackOff; | ||
import org.apache.beam.sdk.util.BackOffUtils; | ||
import org.apache.beam.sdk.util.FluentBackoff; | ||
import org.apache.beam.sdk.util.Sleeper; | ||
import org.joda.time.Duration; | ||
|
||
import java.io.IOException; | ||
import java.io.Serializable; | ||
|
||
public class BackOffExecutor implements Serializable { | ||
|
||
private static FluentBackoff backoff; | ||
|
||
public BackOffExecutor(Integer maxRetries, Duration initialBackOff) { | ||
backoff = FluentBackoff.DEFAULT | ||
.withMaxRetries(maxRetries) | ||
.withInitialBackoff(initialBackOff); | ||
} | ||
|
||
public void execute(Retriable retriable) throws Exception { | ||
Sleeper sleeper = Sleeper.DEFAULT; | ||
BackOff backOff = backoff.backoff(); | ||
while(true) { | ||
try { | ||
retriable.execute(); | ||
break; | ||
} catch (Exception e) { | ||
if(retriable.isExceptionRetriable(e) && BackOffUtils.next(sleeper, backOff)) { | ||
retriable.cleanUpAfterFailure(); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package feast.retry; | ||
|
||
public interface Retriable { | ||
void execute(); | ||
Boolean isExceptionRetriable(Exception e); | ||
void cleanUpAfterFailure(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.