From c6922195a95a14b0ba7f36fadb46629c29a88dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pt=C3=A1=C4=8Dek?= Date: Fri, 5 May 2023 17:45:50 +0200 Subject: [PATCH] staging --- .../android/exporter/PushProxClient.kt | 28 +++++++++-------- .../android/exporter/PushProxWorker.kt | 30 +++++++++++++++++++ local/prometheus.yaml | 2 +- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/client/app/src/main/java/com/birdthedeveloper/prometheus/android/prometheus/android/exporter/PushProxClient.kt b/client/app/src/main/java/com/birdthedeveloper/prometheus/android/prometheus/android/exporter/PushProxClient.kt index 3cfabac..b59ddd8 100644 --- a/client/app/src/main/java/com/birdthedeveloper/prometheus/android/prometheus/android/exporter/PushProxClient.kt +++ b/client/app/src/main/java/com/birdthedeveloper/prometheus/android/prometheus/android/exporter/PushProxClient.kt @@ -178,20 +178,22 @@ class PushProxClient( while (shouldContinue) { log("pushprox main loop", "loop start") // register poll error using try-catch block - try { - doPoll(context) - }catch(e : CancellationException){ - shouldContinue = false - } - catch (e: Exception) { - for(exception in e.suppressed){ - if(exception is CancellationException){ - shouldContinue = false - } + var result = context.backoff.withRetries { + try { + doPoll(context) + }catch(e : CancellationException){ + shouldContinue = false + } + catch (e: Exception) { + for(exception in e.suppressed){ + if(exception is CancellationException){ + shouldContinue = false + } + } + log("exception encountered!", e.toString()) + counters.pollError() + throw e } - log("exception encountered!", e.toString()) - counters.pollError() - throw e } log("pushprox main loop", "loop end") } diff --git a/client/app/src/main/java/com/birdthedeveloper/prometheus/android/prometheus/android/exporter/PushProxWorker.kt b/client/app/src/main/java/com/birdthedeveloper/prometheus/android/prometheus/android/exporter/PushProxWorker.kt index be1b2ae..acf54bf 100644 --- a/client/app/src/main/java/com/birdthedeveloper/prometheus/android/prometheus/android/exporter/PushProxWorker.kt +++ b/client/app/src/main/java/com/birdthedeveloper/prometheus/android/prometheus/android/exporter/PushProxWorker.kt @@ -1,5 +1,6 @@ package com.birdthedeveloper.prometheus.android.prometheus.android.exporter +import android.app.NotificationManager import android.content.Context import android.util.Log import androidx.core.app.NotificationCompat @@ -20,12 +21,18 @@ class PushProxWorker( parameters : WorkerParameters ): CoroutineWorker(context, parameters){ + private val notificationManager = + context.getSystemService(Context.NOTIFICATION_SERVICE) as + NotificationManager + override suspend fun doWork():Result { //TODO implement this val cache: PushProxWorkerCache = PushProxWorkerCache.getInstance { return@getInstance context } + setForeground(createForegroundInfo()) + try{ val pushProxConfig : PushProxConfig = PushProxConfig.fromData(inputData) @@ -38,6 +45,29 @@ class PushProxWorker( return Result.success() } + + private fun createForegroundInfo(): ForegroundInfo { + val id = "channel_id" + val title = "title" + val cancel = "cancel_download" + // This PendingIntent can be used to cancel the worker + val intent = WorkManager.getInstance(applicationContext) + .createCancelPendingIntent(getId()) + + val notification = NotificationCompat.Builder(applicationContext, id) + .setContentTitle(title) + .setTicker(title) + .setContentText("progress") + .setSmallIcon(R.drawable.ic_launcher_foreground) + .setOngoing(true) + // Add the cancel action to the notification which can + // be used to cancel the worker + .addAction(android.R.drawable.ic_delete, cancel, intent) + .build() + + return ForegroundInfo(notificationId, notification) + } + } // thread-safe singleton diff --git a/local/prometheus.yaml b/local/prometheus.yaml index 9cab7b6..842123c 100644 --- a/local/prometheus.yaml +++ b/local/prometheus.yaml @@ -1,6 +1,6 @@ # Prometheus global configuration file global: - scrape_interval: 5s # Set the scrape interval to every 15 seconds. Default is every 1 minute. + scrape_interval: 3s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. scrape_configs: - job_name: "prometheus"