Skip to content

Commit

Permalink
Develop (#39)
Browse files Browse the repository at this point in the history
* Added handling of 429 error code("Rate limit exceeded")

* bump versions of used libs

(cherry picked from commit 0984aed)

* upgrade to gradle wrapper to v5.5.1

* use openjdk 11 on travis build

* update codacy-coverage-reporter to v. 6.0.0

* update gradle task for codacy
  • Loading branch information
stritti authored Sep 3, 2019
1 parent 0984aed commit 662d4b0
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: java
jdk:
- oraclejdk8
- openjdk11
before_install:
- chmod +x ./gradlew
script:
Expand Down
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ dependencies {
testCompile group: 'com.github.tomakehurst', name: 'wiremock', version:'2.23.2'
testCompile group: 'org.slf4j', name: 'slf4j-jdk14', version:'1.7.26'

codacy group: 'com.codacy', name: 'codacy-coverage-reporter', version: '1.0.13'
codacy 'com.github.codacy:codacy-coverage-reporter:-SNAPSHOT'
}

// custom tasks for creating source jar
Expand All @@ -126,6 +126,7 @@ task sendCoverageToCodacy(type: JavaExec, dependsOn: jacocoTestReport) {
main = "com.codacy.CodacyCoverageReporter"
classpath = configurations.codacy
args = [
"report",
"-l",
"Java",
"-r",
Expand All @@ -134,7 +135,7 @@ task sendCoverageToCodacy(type: JavaExec, dependsOn: jacocoTestReport) {
}

task integrationTest(type: Test) {
testClassesDir = sourceSets.integrationTest.output.classesDir
testClassesDirs = project.sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
// This is not needed, but I like to see which tests have run
testLogging {
Expand Down Expand Up @@ -194,5 +195,5 @@ bintray {
}
}

integrationTest.mustRunAfter test
integrationTest.mustRunAfter test

Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Apr 13 17:03:46 CEST 2017
#Thu Jul 11 10:56:19 CEST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip
19 changes: 11 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

##############################################################################
##
Expand Down Expand Up @@ -154,16 +154,19 @@ if $cygwin ; then
esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
# Escape application args
save ( ) {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
exec "$JAVACMD" "$@"
28 changes: 28 additions & 0 deletions src/main/java/com/sybit/airtable/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

/**
* Representation Class of Airtable Tables.
Expand Down Expand Up @@ -197,6 +199,9 @@ public List<T> select(final Query query) throws AirtableException {
if (offset != null) {
list.addAll(this.select(query, offset));
}
} else if (429 == code) {
randomWait();
return select(query);
} else {
HttpResponseExceptionHandler.onResponse(response);
list = null;
Expand All @@ -205,6 +210,17 @@ public List<T> select(final Query query) throws AirtableException {
return list;
}

/**
* Performs a sleep for random time period between 30 and 35 seconds
*/
private void randomWait() {
try {
TimeUnit.SECONDS.sleep(ThreadLocalRandom.current().nextInt(30, 36));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}

/**
* Get <code>List</code> by given offset.
*
Expand Down Expand Up @@ -491,6 +507,9 @@ public T find(final String id) throws AirtableException {

if (200 == code) {
body = response.getBody();
} else if (429 == code) {
randomWait();
return find(id);
} else {
HttpResponseExceptionHandler.onResponse(response);
body = null;
Expand Down Expand Up @@ -538,6 +557,9 @@ public T create(final T item) throws AirtableException, IllegalAccessException,

if (200 == code) {
responseBody = response.getBody();
} else if (429 == code) {
randomWait();
return create(item);
} else {
HttpResponseExceptionHandler.onResponse(response);
}
Expand Down Expand Up @@ -586,6 +608,9 @@ public T update(final T item) throws AirtableException, IllegalAccessException,

if (200 == code) {
responseBody = response.getBody();
} else if (429 == code) {
randomWait();
return update(item);
} else {
HttpResponseExceptionHandler.onResponse(response);
}
Expand Down Expand Up @@ -638,6 +663,9 @@ public boolean destroy(String id) throws AirtableException {
if (200 == code) {
Delete body = response.getBody();
isDeleted = body.isDeleted();
} else if (429 == code) {
randomWait();
return destroy(id);
} else {
isDeleted = false;
HttpResponseExceptionHandler.onResponse(response);
Expand Down

0 comments on commit 662d4b0

Please sign in to comment.