Skip to content

Commit 4c397f4

Browse files
committed
cache path
1 parent c82ee66 commit 4c397f4

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/NotificationPollingService.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ import software.aws.toolkits.core.utils.getLogger
2121
import software.aws.toolkits.jetbrains.core.DefaultRemoteResourceResolverProvider
2222
import software.aws.toolkits.jetbrains.core.RemoteResourceResolverProvider
2323
import java.io.InputStream
24+
import java.nio.file.Path
25+
import java.nio.file.Paths
2426
import java.time.Duration
2527

2628
private const val NOTIFICATION_ENDPOINT = "https://idetoolkits-hostedfiles.amazonaws.com/Notifications/JetBrains/1.json" // TODO: Replace with actual endpoint
27-
private const val NOTIFICATIONS_RESOURCE_PATH = "/software/aws/toolkits/resources/notifications.json"
2829
private const val MAX_RETRIES = 3
2930
private const val RETRY_DELAY_MS = 1000L
3031

@@ -52,18 +53,18 @@ class NotificationPollingServiceImpl :
5253
Disposable {
5354

5455
private var state = State()
55-
private var currentETag: String? = null
5656
private val alarm = AlarmFactory.getInstance().create(Alarm.ThreadToUse.POOLED_THREAD, this)
5757
private val pollingIntervalMs = Duration.ofMinutes(10).toMillis()
5858
private val resourceResolver: RemoteResourceResolverProvider = DefaultRemoteResourceResolverProvider()
5959
private val notificationsResource = object : RemoteResource {
60-
override val name: String = NOTIFICATIONS_RESOURCE_PATH
60+
override val name: String = "notifications.json"
6161
override val urls: List<String> = listOf(NOTIFICATION_ENDPOINT)
6262
override val remoteResolveParser: RemoteResolveParser = NotificationFileValidator
6363
}
6464

6565
data class State(
6666
var currentETag: String? = null,
67+
var cachedFilePath: String? = null
6768
)
6869

6970
override fun getState(): State = state
@@ -96,15 +97,16 @@ class NotificationPollingServiceImpl :
9697
while (retryCount < MAX_RETRIES) {
9798
try {
9899
val newETag = getNotificationETag()
99-
if (newETag == currentETag) {
100+
if (newETag == state.currentETag) {
100101
LOG.debug { "No updates available for notifications" }
101102
return false
102103
}
103-
resourceResolver.get()
104+
val resolvedPath = resourceResolver.get()
104105
.resolve(notificationsResource)
105106
.toCompletableFuture()
106107
.get()
107-
currentETag = newETag
108+
state.currentETag = newETag
109+
state.cachedFilePath = resolvedPath.toString()
108110
return true
109111
} catch (e: Exception) {
110112
lastException = e
@@ -127,6 +129,10 @@ class NotificationPollingServiceImpl :
127129
request.connection.headerFields["ETag"]?.firstOrNull() ?: ""
128130
}
129131

132+
// Helper method to get Path from stored String
133+
fun getCachedPath(): Path? =
134+
state.cachedFilePath?.let { Paths.get(it) }
135+
130136
/**
131137
* Emits telemetry metric for polling failures
132138
*/

0 commit comments

Comments
 (0)