Skip to content

Commit

Permalink
stats update
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Sep 13, 2023
1 parent 5507086 commit 56b3a5f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 48 deletions.
89 changes: 42 additions & 47 deletions public/js/components/pages/mods/Mods.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,47 +79,6 @@ export default {
</tr>
</thead>
<tbody>
<tr v-for="mod in store.list">
<td>
<span class="badge bg-secondary">{{mod.mod_type}}</span>
</td>
<td>{{mod.name}}</td>
<td>
<span class="badge bg-success">
<i class="fa-solid fa-box-open" v-if="mod.source_type == 'cdb'"></i>
<i class="fa-brands fa-git-alt" v-if="mod.source_type == 'git'"></i>
{{mod.source_type}}
</span>
</td>
<td>
<a :href="mod.url" v-if="mod.source_type == 'git'">{{mod.url}}</a>
</td>
<td>
<span class="badge bg-secondary" v-if="mod.version">{{mod.version}}</span>
</td>
<td>
<a class="btn btn-success" v-if="mod.auto_update">
<i class="fa fa-check"></i>
Enabled
</a>
<a class="btn btn-secondary" v-if="!mod.auto_update">
<i class="fa fa-times"></i>
Disabled
</a>
</td>
<td>
<div class="btn-group">
<a class="btn btn-primary">
<i class="fa fa-edit"></i>
Edit
</a>
<a class="btn btn-danger" v-on:click="remove(mod.id)">
<i class="fa fa-times"></i>
Remove
</a>
</div>
</td>
</tr>
<tr>
<td>
<select class="form-control" v-model="add_mod_type">
Expand Down Expand Up @@ -153,27 +112,63 @@ export default {
</td>
</tr>
<tr>
<td></td>
<td></td>
<td>
<span class="badge bg-success">
<i class="fa-solid fa-box-open"></i>
ContentDB
</span>
</td>
<td></td>
<td></td>
<td></td>
<td>
<router-link to="/cdb/browse" class="btn btn-success" :disabled="store.busy">
<i class="fa-solid fa-box-open"></i>
Add from ContentDB
</router-link>
</td>
</tr>
<tr v-for="mod in store.list">
<td>
<span class="badge bg-secondary">{{mod.mod_type}}</span>
</td>
<td>{{mod.name}}</td>
<td>
<span class="badge bg-success">
<i class="fa-solid fa-box-open"></i>
ContentDB
<i class="fa-solid fa-box-open" v-if="mod.source_type == 'cdb'"></i>
<i class="fa-brands fa-git-alt" v-if="mod.source_type == 'git'"></i>
{{mod.source_type}}
</span>
</td>
<td>
<a :href="mod.url" v-if="mod.source_type == 'git'">{{mod.url}}</a>
</td>
<td>
<span class="badge bg-secondary" v-if="mod.version">{{mod.version}}</span>
</td>
<td>
<a class="btn btn-success" v-if="mod.auto_update">
<i class="fa fa-check"></i>
Enabled
</a>
<a class="btn btn-secondary" v-if="!mod.auto_update">
<i class="fa fa-times"></i>
Disabled
</a>
</td>
<td>
<router-link to="/cdb/browse" class="btn btn-success" :disabled="store.busy">
<i class="fa-solid fa-box-open"></i>
Add from ContentDB
</router-link>
<div class="btn-group">
<a class="btn btn-primary">
<i class="fa fa-edit"></i>
Edit
</a>
<a class="btn btn-danger" v-on:click="remove(mod.id)">
<i class="fa fa-times"></i>
Remove
</a>
</div>
</td>
</tr>
</tbody>
Expand Down
4 changes: 4 additions & 0 deletions web/service_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ func (a *Api) StopEngine(w http.ResponseWriter, r *http.Request, claims *types.C

ctx := context.Background()
err = cli.ContainerStop(ctx, c.ID, container.StopOptions{})

// remove stats
current_stats.Store(nil)

Send(w, true, err)
}

Expand Down
8 changes: 7 additions & 1 deletion web/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
"mtui/types/command"
"net/http"
"sync/atomic"
"time"
)

var current_stats atomic.Pointer[command.StatsCommand]
var current_stats_updated atomic.Int64

func (a *Api) StatsEventListener(c chan *bridge.CommandResponse) {
for {
Expand All @@ -22,6 +24,7 @@ func (a *Api) StatsEventListener(c chan *bridge.CommandResponse) {
continue
}
current_stats.Store(sc)
current_stats_updated.Store(time.Now().Unix())
}
}

Expand All @@ -37,8 +40,11 @@ func (a *Api) GetStats(w http.ResponseWriter, r *http.Request, claims *types.Cla
}
sc.Maintenance = a.app.MaintenanceMode.Load()

last_updated := current_stats_updated.Load()
seconds_ago := time.Now().Unix() - last_updated

cs := current_stats.Load()
if cs != nil {
if cs != nil && seconds_ago < 10 {
sc.MaxLag = cs.MaxLag
sc.PlayerCount = cs.PlayerCount
sc.TimeOfDay = cs.TimeOfDay
Expand Down

0 comments on commit 56b3a5f

Please sign in to comment.