Skip to content

Instantly share code, notes, and snippets.

@ayeshLK
Last active March 12, 2023 08:01
Show Gist options
  • Save ayeshLK/29dd9bd1692f0fd83da151ebfa70c06d to your computer and use it in GitHub Desktop.
Save ayeshLK/29dd9bd1692f0fd83da151ebfa70c06d to your computer and use it in GitHub Desktop.
isolated class NotificationSender {
*task:Job;
private final string location;
isolated function init(string location) {
self.location = location;
}
public isolated function execute() {
WeatherReport|error weatherReport = getWeatherReport(self.location);
if weatherReport is error {
log:printWarn(string `Error occurred while retrieving weather-report: ${weatherReport.message()}`, stackTrace = weatherReport.stackTrace());
return;
}
error? persistResult = publishWeatherNotification(self.location, weatherReport);
if persistResult is error {
log:printWarn(string `Error occurred while persisting the weather-report: ${persistResult.message()}`, stackTrace = persistResult.stackTrace());
}
}
}
isolated function startNotificationSender(string location) returns task:JobId|error {
NotificationSender notificationSender = new (location);
// schedule the job to be run every 600 seconds (10 minutes)
return task:scheduleJobRecurByFrequency(notificationSender, 600.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment