-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.bal
64 lines (47 loc) · 1.46 KB
/
client.bal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import ballerina/http;
import ballerina/io;
import ballerina/log;
import ballerina/task;
import ballerina/math;
import ballerina/runtime;
endpoint http:Client clientEndpoint {
url: "http://localhost:9090"
};
task:Timer? timer;
string textTweetID ="0";
function main(string... args) {
(function() returns error?) onTriggerFunction = op;
function(error) onErrorFunction = opError;
timer = new task:Timer(onTriggerFunction, onErrorFunction,
30000, delay = 500);
timer.start();
runtime:sleep(86400000);
}
function op() returns error ? {
io:println("jsonMsg tweetID : " + textTweetID);
http:Request req = new;
json jsonMsg = { lastTweetID: textTweetID, keyword: "#wso2con" };
req.setJsonPayload(jsonMsg);
var response = clientEndpoint->post("/",req);
match response {
http:Response resp => {
var msg = resp.getJsonPayload();
match msg {
json jsonPayload => {
string outTweetID= jsonPayload["latestTweetID"].toString();
io:println("latest tweet ID : " + outTweetID);
textTweetID = outTweetID;
}
error err => {
log:printError(err.message, err = err);
}
}
}
error err => { log:printError(err.message, err = err); }
}
return ();
}
function opError(error e) {
io:print("[ERROR] process failed");
io:println(e);
}