Waiting approvals read again within hours; repairs kept from a channel's first read; abandoned tunes noted (build 68)
22 November 2026, after four days on the VPS: After Dark's 99 moved approvals were still waiting, because its pool wasn't due again for a week after the read that paced out. A pool with approvals still waiting for their provider ID (and not cooling down) is now read again after PARTIAL_POOL_RETRY_MS. Mistletoe's and Sakura's first reads (seedLoop) found their titles but didn't keep the new IDs in their choices; every read now does (keepRefound). And every tune that never shows a picture is noted with how long it was tried and the player's state (Limmy's Show on Orbit Three, Eraserhead on After Dark: both fine on the server now, the reason lost with the log). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -317,6 +317,19 @@ internal class ChannelScheduler(private val store: ScheduleStore,
|
||||
Unplayable.take(itemId)?.let { (title, channel, reason) -> runCatching { store.unplayable().add(itemId, title, channel, reason, clock()) } }
|
||||
}
|
||||
|
||||
/**
|
||||
* Approvals found again under a new ID keep it, so the next read asks for them directly (18 November 2026), whichever
|
||||
* read found them (22 November 2026: a channel's first read didn't keep them). Returns the pool's signature to save.
|
||||
*/
|
||||
private fun keepRefound(userId: String, programming: ChannelProgramming, read: EmbySampleSession.PoolRead): String {
|
||||
val now = store.loadChoices(userId, programming.number)
|
||||
if (read.refound.isEmpty()) return "${programming.signature}#${now.tag}"
|
||||
val moved = ChannelChoices(now.accepted.map { s -> read.refound[s.id]?.let { id -> s.copy(id = id, sourceId = null, durationMs = null) } ?: s }.distinctBy { it.id }, now.rejected)
|
||||
store.saveChoices(userId, programming.number, moved)
|
||||
Log.i("OrbitSchedule", "channel=${programming.number} approvalsRefound=${read.refound.size}")
|
||||
return "${programming.signature}#${moved.tag}"
|
||||
}
|
||||
|
||||
/** Starts a channel that has no loop yet: reads its pool, then gives it a small fallback made from that pool. */
|
||||
fun seedLoop(session: EmbySampleSession, userId: String, programming: ChannelProgramming, checkActive: () -> Unit = {}): SampleChannel {
|
||||
val choices = store.loadChoices(userId, programming.number)
|
||||
@@ -325,7 +338,7 @@ internal class ChannelScheduler(private val store: ScheduleStore,
|
||||
?.let { cached -> loopFromPool(cached.series, programming)?.let { return it } }
|
||||
val read = session.readChannelPool(programming, null, choices, checkActive)
|
||||
val loop = loopFromPool(read.series, programming) ?: throw EmbyCheckException("None of ${programming.name}'s shows were found with episodes to schedule.")
|
||||
store.savePool(userId, programming.number, ScheduleStore.SavedPool(read.series, clock(), "${programming.signature}#${choices.tag}"))
|
||||
store.savePool(userId, programming.number, ScheduleStore.SavedPool(read.series, clock(), keepRefound(userId, programming, read)))
|
||||
return loop
|
||||
}
|
||||
|
||||
@@ -355,7 +368,12 @@ internal class ChannelScheduler(private val store: ScheduleStore,
|
||||
var requests = 0
|
||||
var fetchMs = 0L
|
||||
val routine = cached != null && cached.signature == signature
|
||||
val due = cached == null || cached.signature != signature ||
|
||||
// Approvals still waiting to be found by their provider ID (after a server move, or a read paced out of the hour's
|
||||
// budget) bring the next read forward to a few hours, not a week (22 November 2026: After Dark's 99 waited 4 days).
|
||||
val waiting = cached != null && now - cached.fetchedAtMs >= PARTIAL_POOL_RETRY_MS && choices.accepted.any { a ->
|
||||
a.id.startsWith(MOVED_PREFIX) && a.ref.isNotEmpty() && cached.series.none { it.id == a.id || seriesKey(it.title) == seriesKey(a.title) } &&
|
||||
!IdRepairs.coolingDown(a.type, a.ref, now) }
|
||||
val due = cached == null || cached.signature != signature || waiting ||
|
||||
(poolRefreshDue(cached.fetchedAtMs, number, now) && now - lastRoutineRefreshMs >= POOL_ROUTINE_GAP_MS)
|
||||
if (due) {
|
||||
if (routine) lastRoutineRefreshMs = now
|
||||
@@ -368,14 +386,7 @@ internal class ChannelScheduler(private val store: ScheduleStore,
|
||||
// A refresh that had to keep a few previous copies is tried again in a few hours rather than a week.
|
||||
val fetched = if (read.carried > 0) now - POOL_REFRESH_MS + PARTIAL_POOL_RETRY_MS else now
|
||||
if (read.carried > 0) Log.w("OrbitSchedule", "channel=$number poolRefreshPartial carried=${read.carried}")
|
||||
// Approvals found again under a new ID keep it, so the next read asks for them directly (18 November 2026).
|
||||
val signed = if (read.refound.isEmpty()) signature else {
|
||||
val now2 = store.loadChoices(userId, number)
|
||||
val moved = ChannelChoices(now2.accepted.map { s -> read.refound[s.id]?.let { id -> s.copy(id = id, sourceId = null, durationMs = null) } ?: s }.distinctBy { it.id }, now2.rejected)
|
||||
store.saveChoices(userId, number, moved)
|
||||
Log.i("OrbitSchedule", "channel=$number approvalsRefound=${read.refound.size}")
|
||||
"${programming.signature}#${moved.tag}"
|
||||
}
|
||||
val signed = keepRefound(userId, programming, read)
|
||||
pool = ScheduleStore.SavedPool(read.series, fetched, signed)
|
||||
store.savePool(userId, number, pool)
|
||||
// Stage C, report only: episodes a show here didn't have at the previous read. Never touches the plan.
|
||||
|
||||
@@ -350,6 +350,14 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
|
||||
player.addListener(listener)
|
||||
onDispose {
|
||||
val position = player.currentPosition
|
||||
// Every tune that never showed a picture is noted with how long it was tried and where the player had got to, so
|
||||
// a programme that "didn't work" can be explained afterwards (22 November 2026: Limmy's Show, Eraserhead).
|
||||
if (!ready) {
|
||||
val line = "channel=${scheduled?.channel?.number} item=${plan.item.id} tuneAbandoned afterMs=${SystemClock.elapsedRealtime() - openedAt} " +
|
||||
"state=${player.playbackState} buffered=${player.bufferedPosition} error=${player.playerError?.errorCodeName}"
|
||||
android.util.Log.i("OrbitSchedule", line)
|
||||
PlaybackNotes.add(notes, line)
|
||||
}
|
||||
PlaybackHealth.playing = false
|
||||
lifecycle.removeObserver(observer)
|
||||
player.removeListener(listener)
|
||||
|
||||
@@ -27,6 +27,8 @@ internal object IdRepairs {
|
||||
@Volatile private var file: File? = null
|
||||
private val entries = HashMap<String, Entry>()
|
||||
private val locks = ConcurrentHashMap<String, Any>()
|
||||
/** The time it goes by: the TV's clock, or a test's. */
|
||||
@Volatile var clock: () -> Long = System::currentTimeMillis
|
||||
|
||||
/** The workspace in use: its repairs are its own, as its schedules are. */
|
||||
@Synchronized fun attach(dir: File?) {
|
||||
@@ -44,14 +46,14 @@ internal object IdRepairs {
|
||||
@Synchronized fun known(type: String, ref: String): String? = entries[key(type, ref)]?.id
|
||||
|
||||
/** True while a lookup that found nothing is still cooling down. */
|
||||
@Synchronized fun coolingDown(type: String, ref: String, nowMs: Long = System.currentTimeMillis()): Boolean =
|
||||
@Synchronized fun coolingDown(type: String, ref: String, nowMs: Long = clock()): Boolean =
|
||||
entries[key(type, ref)]?.let { it.id == null && nowMs - it.atMs < cooldownMs(it.fails) } == true
|
||||
|
||||
/**
|
||||
* The item for [ref]: the kept repair, or [fetch] (one lookup, never two at once for the same title, never during a
|
||||
* cooldown). A fetch that finds nothing starts or lengthens the cooldown; one that throws records nothing and throws on.
|
||||
*/
|
||||
fun lookup(type: String, ref: String, nowMs: Long = System.currentTimeMillis(), fetch: () -> String?): String? {
|
||||
fun lookup(type: String, ref: String, nowMs: Long = clock(), fetch: () -> String?): String? {
|
||||
if (ref.isEmpty()) return null
|
||||
val k = key(type, ref)
|
||||
synchronized(locks.getOrPut(k) { Any() }) {
|
||||
@@ -66,7 +68,7 @@ internal object IdRepairs {
|
||||
}
|
||||
|
||||
/** Lookups made elsewhere (a programme refiled for playback) count towards the same cooldowns. */
|
||||
fun found(type: String, ref: String, id: String?, nowMs: Long = System.currentTimeMillis()) { if (ref.isNotEmpty()) record(key(type, ref), id?.takeIf { EmbyClient.validId(it) }, nowMs) }
|
||||
fun found(type: String, ref: String, id: String?, nowMs: Long = clock()) { if (ref.isNotEmpty()) record(key(type, ref), id?.takeIf { EmbyClient.validId(it) }, nowMs) }
|
||||
|
||||
/** A kept repair that's gone stale (the server renumbered again): looked up afresh next time. */
|
||||
@Synchronized fun forget(type: String, ref: String) { if (entries.remove(key(type, ref)) != null) save() }
|
||||
@@ -84,7 +86,7 @@ internal object IdRepairs {
|
||||
runCatching { writeSafely(f, o.toString()) }
|
||||
}
|
||||
|
||||
internal fun resetForTest() { synchronized(this) { file = null; entries.clear() }; locks.clear() }
|
||||
internal fun resetForTest() { synchronized(this) { file = null; entries.clear() }; locks.clear(); clock = System::currentTimeMillis }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user