Skip to content
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

fix misspelling of 'interval' #47

Open
wants to merge 1 commit into
base: main
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Environment variables to configure the backend with:
| QHANA_PORT | `9090` | The port where the backend listens. |
| QHANA_HOST | `http://localhost:9090` | The host base url of the backend including protocol and port. |
| QHANA_CORS_DOMAINS | `http://localhost:4200` | Domains for which cors requests are allowed. Entries are separated by any whitespace. |
| QHANA_WATCHER_INTERVALLS | `1 10 10 5 60` | Configuration for the result watcher intervalls. Event entries are intervalls (in seconds) and odd entries specify after how many iterations the next intervall in the list is used. |
| QHANA_WATCHER_INTERVALS | `1 10 10 5 60` | Configuration for the result watcher intervals. Event entries are intervals (in seconds) and odd entries specify after how many iterations the next interval in the list is used. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing config variable names can have severe consequences (I think this particular config is mostly unused, but this needs to be checked before merging). Also, I want to get the ballerina update through first.

| QHANA_URL_MAPPING | `{"(?<=^\|https?://)localhost(:[0-9]+)?": "host.docker.internal$1"}` | A map of rewrite rules for plugin result URLs. The map is a JSON object whose keys are regex patterns and whose values are the replacement strings for these patterns. All rules are applied to an URL without a guaranteed order. |
| LOCALHOST_PROXY_PORTS | `:1234 :2345` | Alternative to QHANA_URL_MAPPING that can be used with the docker container. Forwards requests that go to the specified ports to the host machine.
| QHANA_PLUGINS | `["http://localhost:5005/plugins/hello-world@v0-1-0/", "http://localhost:5005/plugins/entity-filter@v0-1-0/"]` | A list (JSON list/array) of plugin URLs. |
Expand Down
44 changes: 22 additions & 22 deletions main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ function getHost() returns string {
# The final configured server host.
final string & readonly serverHost = getHost().cloneReadOnly();

# User configurable watcher intervall configuration.
# Can also be configured by setting the `QHANA_WATCHER_INTERVALLS` environment variable.
# The numbers are interpreted as folowing: `[<intervall in seconds>, [<iterations until next intervall>]]*`
# If the list ends with an intervall, i.e., the iterations count is missing, then the intervall
# User configurable watcher interval configuration.
# Can also be configured by setting the `QHANA_WATCHER_INTERVALS` environment variable.
# The numbers are interpreted as folowing: `[<interval in seconds>, [<iterations until next interval>]]*`
# If the list ends with an interval, i.e., the iterations count is missing, then the interval
# will be repeated indefinitely.
configurable (decimal|int)[] watcherIntervallConfig = [2, 10, 5, 10, 10, 60, 30, 20, 60, 10, 600];
configurable (decimal|int)[] watcherIntervalConfig = [2, 10, 5, 10, 10, 60, 30, 20, 60, 10, 600];

# Coerce the string input to a positive int or decimal.
#
Expand All @@ -122,25 +122,25 @@ function coerceToPositiveNumber(string input) returns decimal|int|error {
return error(string `Input "${input}" is not a positive number!`);
}

# Get the watcher intervalls from the `QHANA_WATCHER_INTERVALLS` environment variable.
# If not present use the configurable variable `watcherIntervallConfig` as fallback.
# Get the watcher intervals from the `QHANA_WATCHER_INTERVALS` environment variable.
# If not present use the configurable variable `watcherIntervalConfig` as fallback.
#
# + return - the configured watcher intervalls
function getWatcherIntervallConfig() returns (decimal|int)[] {
string intervalls = os:getEnv("QHANA_WATCHER_INTERVALLS");
if (intervalls.length() > 0) {
# + return - the configured watcher intervals
function getWatcherIntervalConfig() returns (decimal|int)[] {
string intervals = os:getEnv("QHANA_WATCHER_INTERVALS");
if (intervals.length() > 0) {
do {
return from string i in regex:split(intervalls, "[\\s\\(\\),;]+")
return from string i in regex:split(intervals, "[\\s\\(\\),;]+")
select check coerceToPositiveNumber(i);
} on fail error err {
log:printError("Failed to parse environment variable QHANA_WATCHER_INTERVALLS!\n", 'error = err, stackTrace = err.stackTrace());
log:printError("Failed to parse environment variable QHANA_WATCHER_INTERVALS!\n", 'error = err, stackTrace = err.stackTrace());
}
}
return watcherIntervallConfig;
return watcherIntervalConfig;
}

# The final configured watcher intervalls.
final (decimal|int)[] & readonly configuredWatcherIntervalls = getWatcherIntervallConfig().cloneReadOnly();
# The final configured watcher intervals.
final (decimal|int)[] & readonly configuredWatcherIntervals = getWatcherIntervalConfig().cloneReadOnly();

# User configurable URL map which is used by the backend to rewrite URLs used by the result watchers.
# Can also be configured by setting the `QHANA_URL_MAPPING` environment variable.
Expand All @@ -153,7 +153,7 @@ configurable map<string> & readonly internalUrlMap = {};
# Get the URL map from the `QHANA_URL_MAPPING` environment variable.
# If not present use the configurable variable `internalUrlMap` as fallback.
#
# + return - the configured watcher intervalls
# + return - the configured watcher intervals
function getInternalUrlMap() returns map<string> {
string mapping = os:getEnv("QHANA_URL_MAPPING");
if (mapping.length() > 0) {
Expand Down Expand Up @@ -191,7 +191,7 @@ configurable string[] pluginRunners = [];
# Get preset plugin runner from the `QHANA_PLUGIN_RUNNERS` environment variable.
# If not present use the configurable variable `pluginRunners` as fallback.
#
# + return - the configured watcher intervalls
# + return - the configured watcher intervals
function getPluginRunnersConfig() returns string[] {
string pRunners = os:getEnv("QHANA_PLUGIN_RUNNERS");
if (pRunners.length() > 0) {
Expand All @@ -210,7 +210,7 @@ final string[] & readonly preconfiguredPluginRunners = getPluginRunnersConfig().
# Get preset plugins from the `QHANA_PLUGINS` environment variable.
# If not present use the configurable variable `plugins` as fallback.
#
# + return - the configured watcher intervalls
# + return - the configured watcher intervals
function getPluginsConfig() returns string[] {
string pluginList = os:getEnv("QHANA_PLUGINS");
if (pluginList.length() > 0) {
Expand Down Expand Up @@ -705,7 +705,7 @@ service / on new http:Listener(serverPort) {
}
do {
ResultWatcher watcher = check new (createdStep.stepId);
check watcher.schedule(...configuredWatcherIntervalls);
check watcher.schedule(...configuredWatcherIntervals);
} on fail error err {
log:printError("Failed to start watcher.", 'error = err, stackTrace = err.stackTrace());
// if with return does not correctly narrow type for rest of function... this does.
Expand Down Expand Up @@ -869,7 +869,7 @@ service / on new http:Listener(serverPort) {
lock {
watcher = check getResultWatcherFromRegistry(step.stepId);
}
check watcher.schedule(...configuredWatcherIntervalls);
check watcher.schedule(...configuredWatcherIntervals);
} on fail error err {
log:printError("Failed to restart watcher.", 'error = err, stackTrace = err.stackTrace());
// if with return does not correctly narrow type for rest of function... this does.
Expand Down Expand Up @@ -1283,7 +1283,7 @@ public function main() {
var stepsToWatch = check database:getTimelineStepsWithResultWatchers();
foreach var stepId in stepsToWatch {
ResultWatcher watcher = check new (stepId);
check watcher.schedule(...configuredWatcherIntervalls);
check watcher.schedule(...configuredWatcherIntervals);
}
check commit;
} on fail error err {
Expand Down
18 changes: 9 additions & 9 deletions result-watcher.bal
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ isolated class ResultWatcherRescheduler {
public isolated function execute() {
log:printInfo(string `Reschedule watcher ${self.watcher.stepId} after new substep was found.`);
// TODO: Probably needs to be changed in the future
(decimal|int)[] initialIntervals = configuredWatcherIntervalls;
(decimal|int)[] initialIntervals = configuredWatcherIntervals;
error? err = self.watcher.schedule(...initialIntervals);
if err != () {
log:printError("Failed to reschedule watcher.", 'error = err, stackTrace = err.stackTrace());
Expand Down Expand Up @@ -479,7 +479,7 @@ public isolated class ResultWatcher {
}
}

# Unschedule the current repeating task and schedule self again with the new intervall.
# Unschedule the current repeating task and schedule self again with the new interval.
#
# + interval - the time in seconds
# + maxCount - how often the task will be repeated max (-1 for infinite repeats)
Expand Down Expand Up @@ -509,17 +509,17 @@ public isolated class ResultWatcher {
# Schedule this background job periodically with the given interval in seconds.
#
# If more than one number is given every second number starting from the first is
# interpreted as an interval. The number following the intervall is the number of
# times this background job is scheduled with that intervall. If no number follows
# an intervall, then the job will not unschedule itself.
# interpreted as an interval. The number following the interval is the number of
# times this background job is scheduled with that interval. If no number follows
# an interval, then the job will not unschedule itself.
#
# If the number of times is exceeded, then the job will reschedule itself
# with the next intervall in the list. If no intervall is left, then the job
# with the next interval in the list. If no interval is left, then the job
# will unschedule itself.
#
# Unschedules the job first if it was already scheduled.
#
# + intervals - usage: `[intervall1, backoffCounter1, intervall2, backoffCounter2, ..., [intervallLast]]`
# + intervals - usage: `[interval1, backoffCounter1, interval2, backoffCounter2, ..., [intervalast]]`
# + return - The error encountered while (re)scheduling this job (or parsing the intervals)
public isolated function schedule(decimal|int... intervals) returns error? {
if intervals.length() <= 0 {
Expand All @@ -544,12 +544,12 @@ public isolated class ResultWatcher {
self.scheduleIntervals = scheduleIntervals.clone().reverse();
self.backoffCounters = backoffCounters.clone().reverse();

var startingIntervall = self.scheduleIntervals.pop(); // list always contains >1 entries at this point (see guard at top)
var startingInterval = self.scheduleIntervals.pop(); // list always contains >1 entries at this point (see guard at top)
self.currentBackoffCounter = self.backoffCounters.length() > 0 ? self.backoffCounters.pop() : ();

int? maxRuns = self.currentBackoffCounter;

check self.reschedule(startingIntervall, (maxRuns == ()) ? -1 : maxRuns + 1);
check self.reschedule(startingInterval, (maxRuns == ()) ? -1 : maxRuns + 1);
}
}

Expand Down