feat(server/gtfsr): compress after every day
This commit is contained in:
parent
102c028407
commit
b31067992d
1 changed files with 9 additions and 2 deletions
|
|
@ -41,13 +41,19 @@ internal class GtfsrtArchiver {
|
||||||
|
|
||||||
val time = Instant.fromEpochSeconds(timestamp).toLocalDateTime(TimeZone.currentSystemDefault())
|
val time = Instant.fromEpochSeconds(timestamp).toLocalDateTime(TimeZone.currentSystemDefault())
|
||||||
|
|
||||||
|
val (prevWeek, prevDay) = (time.dayOfYear - 1) / 7 to (time.dayOfYear - 1) % 7
|
||||||
|
val (nextWeek, nextDay) = time.dayOfYear / 7 to time.dayOfYear % 7
|
||||||
|
|
||||||
val base = File(BASE_DIR, type)
|
val base = File(BASE_DIR, type)
|
||||||
val previousParent = File(base, "${time.year}-${((time.dayOfYear - 1) / 7).toString().padStart(2, '0')}")
|
val previousParent = File(base, "${time.year}-${prevWeek.toString().padStart(2, '0')}/${prevDay}")
|
||||||
val currentParent = File(base, "${time.year}-${((time.dayOfYear - 1) / 7 + 1).toString().padStart(2, '0')}")
|
val currentParent = File(base, "${time.year}-${nextWeek.toString().padStart(2, '0')}/${nextDay}")
|
||||||
val target = File(currentParent, "${timestamp}.proto")
|
val target = File(currentParent, "${timestamp}.proto")
|
||||||
|
|
||||||
if (previousParent.isDirectory) {
|
if (previousParent.isDirectory) {
|
||||||
enqueueCompression(previousParent)
|
enqueueCompression(previousParent)
|
||||||
|
if (prevWeek != nextWeek) {
|
||||||
|
enqueueCompression(previousParent.parentFile)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!target.exists()) {
|
if (!target.exists()) {
|
||||||
|
|
@ -90,6 +96,7 @@ internal class GtfsrtArchiver {
|
||||||
).start()
|
).start()
|
||||||
val exitCode = proc.waitFor()
|
val exitCode = proc.waitFor()
|
||||||
if (exitCode == 0) {
|
if (exitCode == 0) {
|
||||||
|
log("CompressJob", "Compressed ${next.absolutePath} to ${next.absolutePath}.tar.zst")
|
||||||
if (next.deleteRecursively()) {
|
if (next.deleteRecursively()) {
|
||||||
cmut.withLock { cqueue.remove(next) }
|
cmut.withLock { cqueue.remove(next) }
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue