Skip to content

Commit

Permalink
removed updateAttributes() because it did not help with issue #25
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuth committed Jun 4, 2024
1 parent 6b7b98e commit f81f27f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ val job = ippPrinter.printJob(
PrintQuality.High,
Media.ISO_A4,
mediaColWithSource("tray-1"),
notifyEvents = listOf("job-state-changed", "job-stopped", "job-completed") // CUPS
notifyEvents = listOf("job-state-changed", "job-progress") // CUPS
)
job.subscription?.pollAndHandleNotifications { println(it) }

Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/de/gmuth/ipp/client/IppSubscription.kt
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,12 @@ class IppSubscription(

@JvmOverloads
fun pollAndHandleNotifications(
pollEvery: Duration = ofSeconds(5), // should be larger than 1s
pollEvery: Duration = ofSeconds(1),
autoRenewSubscription: Boolean = false,
handleNotification: (event: IppEventNotification) -> Unit = { logger.info { it.toString() } }
) {
fun expiresAfterDelay() = expiresAt != null && now().plus(pollEvery).isAfter(expiresAt!!.minusSeconds(2))
try {
updateAttributes()
pollHandlesNotifications = true
while (pollHandlesNotifications) {
if (expiryAvailable() && expired()) logger.warning { "Subscription #$id has expired" }
Expand All @@ -154,7 +153,8 @@ class IppSubscription(
Thread.sleep(pollEvery.toMillis())
}
} catch (clientErrorNotFoundException: ClientErrorNotFoundException) {
logger.info { clientErrorNotFoundException.response.statusMessage.toString() }
// Subscription ends on job termination. CUPS than responds with "Subscription #... does not exist."
logger.fine { "${clientErrorNotFoundException.response.statusMessage}" }
}
}

Expand Down

0 comments on commit f81f27f

Please sign in to comment.