Skip to content

Commit

Permalink
Support lifecycle configuration for records in database
Browse files Browse the repository at this point in the history
  • Loading branch information
bclswl0827 committed Mar 31, 2024
1 parent acb4660 commit 7133eaa
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 17 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

Starting from v2.2.5, all notable changes to this project will be documented in this file.

## v2.12.0

- Support lifecycle configuration for records in database

## v2.11.10

- Set minimum TLS version to 1.2 for HTTP request utility
- Update frontend dependencies

## v2.11.9

- Show free disk space in banner instead of station UUID
- Show disk free space in banner instead of station UUID

## v2.11.8

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.11.10
v2.12.0
3 changes: 2 additions & 1 deletion build/assets/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"port": 5432,
"username": "postgres",
"password": "passw0rd",
"database": "observer"
"database": "observer",
"lifecycle": 10
},
"server_settings": {
"host": "0.0.0.0",
Expand Down
15 changes: 8 additions & 7 deletions config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ type ntpclient struct {
}

type archiver struct {
Engine string `json:"engine"`
Enable bool `json:"enable"`
Host string `json:"host"`
Port int `json:"port"`
Username string `json:"username"`
Password string `json:"password"`
Database string `json:"database"`
Engine string `json:"engine"`
Enable bool `json:"enable"`
Host string `json:"host"`
Port int `json:"port"`
LifeCycle int `json:"lifecycle"`
Username string `json:"username"`
Password string `json:"password"`
Database string `json:"database"`
}

type server struct {
Expand Down
8 changes: 8 additions & 0 deletions driver/dao/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dao

import "gorm.io/gorm"

func Delete(db *gorm.DB, start, end int64) error {
var records []dbRecord
return db.Table(DB_TABLENAME).Where("ts >= ? AND ts <= ?", start, end).Delete(&records).Error
}
32 changes: 32 additions & 0 deletions feature/archiver/cleanup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package archiver

import (
"time"

"github.com/anyshake/observer/driver/dao"
"github.com/anyshake/observer/publisher"
"github.com/anyshake/observer/utils/duration"
"gorm.io/gorm"
)

func (a *Archiver) handleCleanup(status *publisher.Status, db *gorm.DB, lifeCycle int) {
for {
// Wait until system is ready
if status.ReadyTime.IsZero() {
time.Sleep(time.Second)
continue
}

// Get start and end time
currentTime, _ := duration.Timestamp(status.System.Offset)
endTime := currentTime.Add(-time.Duration(lifeCycle) * time.Hour * 24)

// Remove expired records
err := dao.Delete(db, 0, endTime.UnixMilli())
if err != nil {
a.OnError(nil, err)
}

time.Sleep(time.Hour)
}
}
6 changes: 6 additions & 0 deletions feature/archiver/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ func (a *Archiver) Run(options *feature.FeatureOptions, waitGroup *sync.WaitGrou
}
options.Database = pdb

// Start cleanup routine if life cycle bigger than 0
lifeCycle := options.Config.MiniSEED.LifeCycle
if lifeCycle > 0 {
go a.handleCleanup(options.Status, pdb, lifeCycle)
}

// Archive when new message arrived
expressionForSubscribe := true
go func() {
Expand Down
4 changes: 2 additions & 2 deletions frontend/dist/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"files": {
"main.css": "./static/css/main.7a040865.css",
"main.js": "./static/js/main.f9ed9c3f.js",
"main.js": "./static/js/main.6ea9d68f.js",
"static/css/594.d6bfd15f.chunk.css": "./static/css/594.d6bfd15f.chunk.css",
"static/js/594.7755917b.chunk.js": "./static/js/594.7755917b.chunk.js",
"static/js/846.88ce4ddb.chunk.js": "./static/js/846.88ce4ddb.chunk.js",
Expand Down Expand Up @@ -49,6 +49,6 @@
},
"entrypoints": [
"static/css/main.7a040865.css",
"static/js/main.f9ed9c3f.js"
"static/js/main.6ea9d68f.js"
]
}
2 changes: 1 addition & 1 deletion frontend/dist/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html><head><meta charset="utf-8"/><link rel="icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/><link rel="apple-touch-icon" href="./logo192.png"/><link rel="manifest" href="./manifest.json"/><style>.public-loading{width:100%;height:100%;display:flex;position:fixed;align-items:center;flex-direction:column;justify-content:center}.public-loading span{color:#1f2937;margin-top:20px;font-weight:600;font-size:1.25rem}.public-loading svg{animation:rotate 1s linear infinite}@keyframes rotate{100%{transform:rotate(360deg)}}</style><script defer="defer" src="./static/js/main.f9ed9c3f.js"></script><link href="./static/css/main.7a040865.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div class="public-loading"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="#6b21a8" width="70px"><path d="M304 48a48 48 0 1 0 -96 0 48 48 0 1 0 96 0zm0 416a48 48 0 1 0 -96 0 48 48 0 1 0 96 0zM48 304a48 48 0 1 0 0-96 48 48 0 1 0 0 96zm464-48a48 48 0 1 0 -96 0 48 48 0 1 0 96 0zM142.9 437A48 48 0 1 0 75 369.1 48 48 0 1 0 142.9 437zm0-294.2A48 48 0 1 0 75 75a48 48 0 1 0 67.9 67.9zM369.1 437A48 48 0 1 0 437 369.1 48 48 0 1 0 369.1 437z"/></svg> <span>Loading...</span></div><div id="root"></div></body></html>
<!doctype html><html><head><meta charset="utf-8"/><link rel="icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/><link rel="apple-touch-icon" href="./logo192.png"/><link rel="manifest" href="./manifest.json"/><style>.public-loading{width:100%;height:100%;display:flex;position:fixed;align-items:center;flex-direction:column;justify-content:center}.public-loading span{color:#1f2937;margin-top:20px;font-weight:600;font-size:1.25rem}.public-loading svg{animation:rotate 1s linear infinite}@keyframes rotate{100%{transform:rotate(360deg)}}</style><script defer="defer" src="./static/js/main.6ea9d68f.js"></script><link href="./static/css/main.7a040865.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div class="public-loading"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="#6b21a8" width="70px"><path d="M304 48a48 48 0 1 0 -96 0 48 48 0 1 0 96 0zm0 416a48 48 0 1 0 -96 0 48 48 0 1 0 96 0zM48 304a48 48 0 1 0 0-96 48 48 0 1 0 0 96zm464-48a48 48 0 1 0 -96 0 48 48 0 1 0 96 0zM142.9 437A48 48 0 1 0 75 369.1 48 48 0 1 0 142.9 437zm0-294.2A48 48 0 1 0 75 75a48 48 0 1 0 67.9 67.9zM369.1 437A48 48 0 1 0 437 369.1 48 48 0 1 0 369.1 437z"/></svg> <span>Loading...</span></div><div id="root"></div></body></html>
2 changes: 2 additions & 0 deletions frontend/dist/static/js/main.6ea9d68f.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions frontend/dist/static/js/main.f9ed9c3f.js

This file was deleted.

4 changes: 2 additions & 2 deletions frontend/src/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
REACT_APP_VERSION=v2.11.10
REACT_APP_RELEASE=67a28d40-20240325113004
REACT_APP_VERSION=v2.12.0
REACT_APP_RELEASE=acb4660e-20240331211832

0 comments on commit 7133eaa

Please sign in to comment.