Skip to content

Commit

Permalink
make logs be in proper order
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcooper committed Aug 17, 2023
1 parent aa804b4 commit 01ffc55
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
8 changes: 7 additions & 1 deletion client/src/main/Player.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,10 @@
{/if}
</div>

<PlayList {items} numStopsetsToDisableAddMoreAt={$config.STOPSET_PRELOAD_COUNT + numExtraStopsetsToDisableAddMoreAt} {addStopset} {processItem} {pause} />
<PlayList
{items}
numStopsetsToDisableAddMoreAt={$config.STOPSET_PRELOAD_COUNT + numExtraStopsetsToDisableAddMoreAt}
{addStopset}
{processItem}
{pause}
/>
17 changes: 10 additions & 7 deletions client/src/stores/client-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,28 @@ import { client_log_entry_types } from "../../../server/constants.json"
import { IS_DEV } from "../utils"
import { conn, messageServer } from "./connection"

let pendingLogs = {}
let pendingLogs = new Map()
try {
pendingLogs = JSON.parse(window.localStorage.getItem("pending-logs")) || {}
} catch {}
pendingLogs = new Map(JSON.parse(window.localStorage.getItem("pending-logs")) || [])
} catch (e) {
console.warn("Error loading pendingLog:", e)
}

const savePendingLogs = () => window.localStorage.setItem("pending-logs", JSON.stringify(pendingLogs, null, ""))
const savePendingLogs = () =>
window.localStorage.setItem("pending-logs", JSON.stringify(Array.from(pendingLogs.entries()), null, ""))

export const log = (window.log = (type = "unspecified", description = "") => {
if (!client_log_entry_types.includes(type)) {
console.error(`Invalid log type: ${type} - using unspecified`)
type = "unspecified"
}

pendingLogs[uuid()] = { created_at: dayjs().toISOString(), type, description }
pendingLogs.set(uuid(), { created_at: dayjs().toISOString(), type, description })
savePendingLogs()
})

export const sendPendingLogs = (forceClear = false) => {
const entries = Object.entries(pendingLogs)
const entries = Array.from(pendingLogs.entries())
if (entries.length) {
const { authenticated, connected } = get(conn)
if (authenticated && connected) {
Expand All @@ -41,7 +44,7 @@ export const sendPendingLogs = (forceClear = false) => {
}

export const acknowledgeLog = (id) => {
delete pendingLogs[id]
pendingLogs.delete(id)
savePendingLogs()
}

Expand Down
14 changes: 9 additions & 5 deletions client/src/stores/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ class GeneratedStopsetAssetBase {
return this.beforeActive
}

get logLine() {
const stopset = this.generatedStopset
return `[Stopset=${stopset.name}] [Rotator=${this.rotator.name}] [${this.index + 1}/${
stopset.items.length
}] [Asset=${this.name}]`
}

done() {
this.playing = false
this.generatedStopset.donePlaying()
Expand Down Expand Up @@ -196,10 +203,7 @@ class PlayableAsset extends GeneratedStopsetAssetBase {

done() {
clearInterval(this.interval)
log(
this.didSkip ? "skipped_asset" : "played_asset",
`[Stopset=${this.generatedStopset.name}] [Rotator=${this.rotator.name}] [Asset=${this.name}]`
)
log(this.didSkip ? "skipped_asset" : "played_asset", this.logLine)
super.done()
}

Expand Down Expand Up @@ -317,7 +321,7 @@ export class GeneratedStopset {
if (subindex !== null) {
this.didSkip = this.didSkip || subindex !== this.current
this.items.slice(this.current, subindex).forEach((item) => {
log("skipped_asset", `[Stopset=${this.name}] [Rotator=${item.rotator.name}] [Asset=${item.name}]`)
log("skipped_asset", item.logLine)
if (item.playable) {
item.pause()
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const tomatoIcon = {
if (IS_DEV) {
const originalSetInterval = setInterval
const originalClearInterval = clearInterval
const intervals = window.activeIntervals = new Set()
const intervals = (window.activeIntervals = new Set())
window.setInterval = (...args) => {
const id = originalSetInterval(...args)
intervals.add(id)
Expand Down
2 changes: 1 addition & 1 deletion server/tomato/models/client_log_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ class Meta:
verbose_name = "client log entry"
verbose_name_plural = "client log entries"
db_table = "logs"
ordering = ("-created_at",)
ordering = ("-created_at", "-id")
4 changes: 4 additions & 0 deletions server/tomato/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@
USE_I18N = True
USE_TZ = True

# Let nginx handle these
DATA_UPLOAD_MAX_NUMBER_FIELDS = None
DATA_UPLOAD_MAX_MEMORY_SIZE = None

STATIC_URL = "/static/"
STATIC_ROOT = "/serve/static"
MEDIA_URL = "/assets/"
Expand Down

0 comments on commit 01ffc55

Please sign in to comment.