Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import software.aws.toolkits.core.utils.RemoteResolveParser
import software.aws.toolkits.core.utils.RemoteResource
import software.aws.toolkits.core.utils.error
import software.aws.toolkits.core.utils.getLogger
import software.aws.toolkits.core.utils.info
import software.aws.toolkits.core.utils.warn
import software.aws.toolkits.jetbrains.core.DefaultRemoteResourceResolverProvider
import software.aws.toolkits.jetbrains.core.RemoteResourceResolverProvider
Expand Down Expand Up @@ -77,20 +78,24 @@ internal final class NotificationPollingService : Disposable {
var lastException: Exception? = null

while (retryCount < MAX_RETRIES) {
LOG.info { "Polling for notifications" }
try {
val newETag = getNotificationETag()
if (newETag == NotificationEtagState.getInstance().etag) {
// for when we need to notify on first poll even when there's no new ETag
if (isFirstPoll.compareAndSet(true, false)) {
notifyObservers()
LOG.info { "No new notifications, checking cached notifications on first poll" }
return true
}
LOG.info { "No new notifications to fetch" }
return false
}
resourceResolver.get()
.resolve(notificationsResource)
.toCompletableFuture()
.get()
NotificationEtagState.getInstance().etag = newETag
LOG.info { "New notifications fetched" }
return true
} catch (e: Exception) {
lastException = e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import com.intellij.openapi.application.PathManager
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import software.aws.toolkits.core.utils.getLogger
import software.aws.toolkits.core.utils.info
import software.aws.toolkits.core.utils.inputStream
import software.aws.toolkits.jetbrains.utils.notifyStickyWithData
import java.nio.file.Paths
Expand Down Expand Up @@ -45,6 +47,7 @@ class ProcessNotificationsBase(

fun retrieveStartupAndEmergencyNotifications() {
val isStartupPoll = isStartup.compareAndSet(true, false)
LOG.info { "Retrieving notifications for processing. StartUp notifications included: $isStartupPoll" }
val notifications = getNotificationsFromFile()
notifications?.let { notificationsList ->
val activeNotifications = notificationsList.notifications
Expand All @@ -61,11 +64,13 @@ class ProcessNotificationsBase(

activeNotifications.forEach { processNotification(project, it) }
}
LOG.info { "Finished processing notifications" }
}

fun processNotification(project: Project, notificationData: NotificationData) {
val shouldShow = RulesEngine.displayNotification(project, notificationData)
if (shouldShow) {
LOG.info { "Showing notification with id: ${notificationData.id}" }
val notificationContent = notificationData.content.locale
val severity = notificationData.severity
val followupActions = NotificationManager.createActions(
Expand Down Expand Up @@ -105,6 +110,7 @@ class ProcessNotificationsBase(
notifListener.add(newNotifListener)

companion object {
private val LOG = getLogger<ProcessNotificationsBase>()
fun getInstance(project: Project): ProcessNotificationsBase = project.service()

private const val NOTIFICATIONS_PATH = "aws-static-resources/notifications.json"
Expand Down
Loading