This commit is contained in:
Martin Ptáček
2023-05-05 17:45:50 +02:00
parent 84e347a423
commit c6922195a9
3 changed files with 46 additions and 14 deletions

View File

@ -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")
}

View File

@ -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

View File

@ -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"