Skip to content

Added option on job to specify waitRetryDelay and bumped API version … #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class Blitline {
/**
* The API version this library will invoke. 1.21 added the ability to append arbitrary EXIF to saved images.
*/
public static final String BLITLINE_API_VERSION = "1.21";
public static final String BLITLINE_API_VERSION = "1.22";

private Blitline() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class BlitlineImageJob implements Serializable {
private final Boolean extendedMetadata;
private final String postbackUrl;
private final Map<String, String> postbackHeaders;
private final Integer waitRetryDelay;
private final List<Function> functions = new LinkedList<Function>();

public BlitlineImageJob(String applicationId, Object src, Boolean extendedMetadata, String postbackUrl) {
Expand All @@ -42,6 +43,15 @@ public BlitlineImageJob(String applicationId, Object src, Boolean extendedMetada

public BlitlineImageJob(String applicationId, Object src, Boolean extendedMetadata, String postbackUrl,
Map<String, String> postbackHeaders) {
this(applicationId, src, extendedMetadata, postbackUrl, postbackHeaders, null);
}

public BlitlineImageJob(String applicationId,
Object src,
Boolean extendedMetadata,
String postbackUrl,
Map<String, String> postbackHeaders,
Integer waitRetryDelay) {
Validate.notNull(applicationId, "application ID must not be null");
this.applicationId = applicationId;

Expand All @@ -53,7 +63,10 @@ public BlitlineImageJob(String applicationId, Object src, Boolean extendedMetada
this.postbackUrl = postbackUrl;

this.postbackHeaders = postbackHeaders == null ? null : Collections.unmodifiableMap(new HashMap<String, String>(
postbackHeaders));
postbackHeaders));

if (waitRetryDelay != null) Validate.inclusiveBetween(0, Integer.MAX_VALUE, waitRetryDelay);
this.waitRetryDelay = waitRetryDelay;
}

public String getApplicationId() {
Expand All @@ -76,12 +89,22 @@ public Map<String, String> getPostbackHeaders() {
return postbackHeaders;
}

/**
* Retrieve the value (in seconds) for wait_retry_delay which determines how long time Blitline will wait before it retries a failed job.
* If not set, then Blitline will not retry a failed job.
*
* @return The value (in seconds) for wait_retry_delay
*/
public Integer getWaitRetryDelay() {
return waitRetryDelay;
}

/**
* Retrieve the value that will be set on the specified HTTP header on the job postback, or {@code null} if the named header is
* not set.
*
* @param name the name of the HTTP header
* @return
* @return The value for the specified header (or null if the header is not set)
*/
public String getPostbackHeader(String name) {
if (postbackHeaders == null) {
Expand Down Expand Up @@ -124,6 +147,8 @@ public static class Builder {

private Map<String, String> postbackHeaders = new HashMap<String, String>();

private Integer waitRetryDelay;

/**
* Constructs a {@code Builder} instance for a single {@code Job}.
*
Expand Down Expand Up @@ -249,6 +274,17 @@ public Builder withExtendedMetadata() {
return this;
}

/**
* Specifies that Blitline should retry a failed job after this amount of second.
*
* @param waitRetryDelay The wait retry delay in seconds
* @return this {@code Builder} object
*/
public Builder withWaitRetryDelay(Integer waitRetryDelay) {
this.waitRetryDelay = waitRetryDelay;
return this;
}

/**
* Build the job and apply one or more functions.
*
Expand All @@ -258,7 +294,7 @@ public Builder withExtendedMetadata() {
*/
public BlitlineImageJob apply(Function... functions) {
Map<String, String> postbackHeaders = this.postbackHeaders.isEmpty() ? null : this.postbackHeaders;
BlitlineImageJob job = new BlitlineImageJob(applicationId, src, extendedMetadata, postbackUrl, postbackHeaders);
BlitlineImageJob job = new BlitlineImageJob(applicationId, src, extendedMetadata, postbackUrl, postbackHeaders, waitRetryDelay);
job.apply(functions);
return job;
}
Expand Down