Skip to content

Commit a876a93

Browse files
authored
Merge pull request #9 from RelationalAI/hnr-fix-build-failure
Fix build failure + anticipate access token expiration
2 parents 4942f53 + 2d605fd commit a876a93

File tree

11 files changed

+84
-8
lines changed

11 files changed

+84
-8
lines changed

.github/workflows/maven-build.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: build/test
22

3-
on: [push]
3+
on:
4+
push:
5+
schedule:
6+
- cron: '30 5 * * *'
47

58
jobs:
69
build:

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
## latest
1+
## v0.2.2-alpha (latest)
2+
* Fixed `getTransaction` missing required properties: [finished_at].
3+
* Added `deleteTransaction`.
4+
5+
## v0.2.1-alpha
26
* Fixed `executeAsync` inputs issue.
37

48
## v0.2.0-alpha

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ In order to use the `rai-sdk-java`, you need add this dependency to your project
8686
<dependency>
8787
<groupId>com.relationalai</groupId>
8888
<artifactId>rai-sdk</artifactId>
89-
<version>0.2.1-alpha</version>
89+
<version>0.2.2-alpha</version>
9090
</dependency>
9191

9292
You need also to point maven to the SDK GitHub packages repository in the project's POM:

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<description>The RelationalAI Software Development Kit (SDK) for Java</description>
2222
<groupId>com.relationalai</groupId>
2323
<artifactId>rai-sdk-pom</artifactId>
24-
<version>0.2.1-alpha</version>
24+
<version>0.2.2-alpha</version>
2525
<packaging>pom</packaging>
2626
<url></url>
2727

rai-sdk-examples/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<parent>
2121
<groupId>com.relationalai</groupId>
2222
<artifactId>rai-sdk-pom</artifactId>
23-
<version>0.2.1-alpha</version>
23+
<version>0.2.2-alpha</version>
2424
</parent>
2525

2626
<name>RelationalAI SDK for Java Examples</name>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2022 RelationalAI, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"): you may
5+
* not use this file except in compliance with the License. You may obtain
6+
* a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package com.relationalai.examples;
18+
19+
import com.relationalai.Client;
20+
import com.relationalai.Config;
21+
import com.relationalai.HttpError;
22+
import com.relationalai.Json;
23+
24+
import java.io.IOException;
25+
26+
public class DeleteTransaction implements Runnable {
27+
String id, profile;
28+
29+
public void parseArgs(String[] args) {
30+
var c = Command.create("DeleteTransaction")
31+
.addArgument("id")
32+
.addOption("profile", "config profile (default: default)")
33+
.parseArgs(args);
34+
this.id = c.getValue("id");
35+
this.profile = c.getValue("profile");
36+
}
37+
38+
public void run(String[] args) throws HttpError, InterruptedException, IOException {
39+
parseArgs(args);
40+
var cfg = Config.loadConfig("~/.rai/config", profile);
41+
var client = new Client(cfg);
42+
43+
var rsp = client.deleteTransaction(id);
44+
Json.print(rsp);
45+
}
46+
}

rai-sdk/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<parent>
2121
<groupId>com.relationalai</groupId>
2222
<artifactId>rai-sdk-pom</artifactId>
23-
<version>0.2.1-alpha</version>
23+
<version>0.2.2-alpha</version>
2424
</parent>
2525

2626
<name>RelationalAI SDK for Java Package</name>

rai-sdk/src/main/java/com/relationalai/AccessToken.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ long nowEpochSecs() {
4343
}
4444

4545
// Answers if the token is expired.
46+
// Anticipate access token expiration by 5 seconds
4647
public boolean isExpired() {
47-
return nowEpochSecs() > expiresOn();
48+
return nowEpochSecs() > expiresOn() - 5;
4849
}
4950
}

rai-sdk/src/main/java/com/relationalai/Client.java

+5
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,11 @@ public List<Object> getTransactionProblems(String id) throws HttpError, IOExcept
809809
return parseProblemsResult(rsp);
810810
}
811811

812+
public TransactionAsyncDeleteResponse deleteTransaction(String id) throws HttpError, IOException, InterruptedException {
813+
var rsp = (String) delete(String.format("%s/%s", PATH_TRANSACTIONS, id));
814+
return Json.deserialize(rsp, TransactionAsyncDeleteResponse.class);
815+
}
816+
812817
// EDBs
813818

814819
public Edb[] listEdbs(String database, String engine)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.relationalai;
2+
3+
import com.jsoniter.annotation.JsonProperty;
4+
5+
public class TransactionAsyncDeleteResponse {
6+
@JsonProperty(value = "txn_id", required = true)
7+
public String id;
8+
9+
@JsonProperty(value = "message", required = true)
10+
public String message;
11+
12+
public TransactionAsyncDeleteResponse() {}
13+
public TransactionAsyncDeleteResponse(String id, String state) {
14+
this.id = id;
15+
this.message = state;
16+
}
17+
}

rai-sdk/src/main/java/com/relationalai/TransactionAsyncResponse.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class TransactionAsyncResponse extends TransactionAsyncCompactResponse {
1212
@JsonProperty(value = "created_on", required = true)
1313
public Long createdOn;
1414

15-
@JsonProperty(value = "finished_at", required = true)
15+
@JsonProperty(value = "finished_at")
1616
public Long finishedAt;
1717

1818
@JsonProperty(value = "database_name", required = true)

0 commit comments

Comments
 (0)