Skip to content

Commit

Permalink
Merge pull request #182 from ECLK/revert-180-master
Browse files Browse the repository at this point in the history
Revert "Replace the timer service task with an async invocation"
  • Loading branch information
MaryamZi authored Aug 6, 2020
2 parents 5f73be6 + f1d5d54 commit c0d469f
Showing 1 changed file with 20 additions and 40 deletions.
60 changes: 20 additions & 40 deletions distributor/src/distributor/website.bal
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import ballerina/auth;
import ballerina/file;
import ballerina/http;
import ballerina/lang.'object;
import ballerina/log;
import ballerina/mime;
import ballerina/runtime;
import ballerina/task;
import ballerina/time;
import ballerina/xmlutils;

Expand Down Expand Up @@ -472,6 +471,25 @@ function generateParliamentaryResultsTable() returns string {
return tab;
}

task:TimerConfiguration timerConfiguration = {
intervalInMillis: 30000,
initialDelayInMillis: 30000
};
listener task:Listener timer = new (timerConfiguration);

service timerService on timer {
resource function onTrigger() {
string[] keys = jsonConnections.keys();
foreach string k in keys {
http:WebSocketCaller? con = jsonConnections[k];
if !(con is ()) {
log:printDebug("Pinging " + con.getConnectionId());
_ = start ping(con);
}
}
}
}

function getUsername(http:Request request) returns string? {
if !request.hasHeader(http:AUTH_HEADER) {
return;
Expand Down Expand Up @@ -502,41 +520,3 @@ function ping(http:WebSocketCaller con) {
log:printError(string `Error pinging ${con.getConnectionId()}`, err);
}
}

function pingSubscribers() {
while true {
string[] keys = jsonConnections.keys();
foreach string k in keys {
http:WebSocketCaller? con = jsonConnections[k];
if !(con is ()) {
log:printDebug("Pinging " + con.getConnectionId());
_ = start ping(con);
}
}
runtime:sleep(30000);
}
}

type PingListener object {
*'object:Listener;

public function __attach(service s, string? name) returns error? {
}

public function __detach(service s) returns error? {
}

public function __start() returns error? {
_ = @strand {thread: "any"} start pingSubscribers();
}

public function __gracefulStop() returns error? {
}

public function __immediateStop() returns error? {
}
};

service PingingService on new PingListener() {

}

0 comments on commit c0d469f

Please sign in to comment.