Last active
March 12, 2023 08:01
-
-
Save ayeshLK/29dd9bd1692f0fd83da151ebfa70c06d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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