mirror of
https://github.com/simon987/task_tracker.git
synced 2025-04-18 01:46:45 +00:00
Clear old monitoring snapshots, logout endpoint
This commit is contained in:
parent
a6802c7109
commit
a90b73ad70
@ -77,6 +77,13 @@ func (api *WebAPI) Login(r *Request) {
|
||||
}).Info("Logged in")
|
||||
}
|
||||
|
||||
func (api *WebAPI) Logout(r *Request) {
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess.Clear()
|
||||
r.Ctx.Response.SetStatusCode(204)
|
||||
}
|
||||
|
||||
func (api *WebAPI) Register(r *Request) {
|
||||
|
||||
req := &RegisterRequest{}
|
||||
|
@ -102,6 +102,7 @@ func New() *WebAPI {
|
||||
|
||||
api.router.POST("/register", LogRequestMiddleware(api.Register))
|
||||
api.router.POST("/login", LogRequestMiddleware(api.Login))
|
||||
api.router.GET("/logout", LogRequestMiddleware(api.Logout))
|
||||
api.router.GET("/account", LogRequestMiddleware(api.AccountDetails))
|
||||
|
||||
api.router.NotFound = func(ctx *fasthttp.RequestCtx) {
|
||||
|
@ -21,5 +21,5 @@ session:
|
||||
expiration: "25m"
|
||||
|
||||
monitoring:
|
||||
snapshot_interval: "10s"
|
||||
history_length: "3000h"
|
||||
snapshot_interval: "60s"
|
||||
history_length: "4h"
|
||||
|
@ -2,6 +2,7 @@ package storage
|
||||
|
||||
import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/simon987/task_tracker/config"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -19,7 +20,7 @@ func (database *Database) MakeProjectSnapshots() {
|
||||
startTime := time.Now()
|
||||
db := database.getDB()
|
||||
|
||||
_, err := db.Exec(`
|
||||
insertRes, err := db.Exec(`
|
||||
INSERT INTO project_monitoring_snapshot
|
||||
(project, new_task_count, failed_task_count, closed_task_count, worker_access_count,
|
||||
awaiting_verification_task_count, timestamp)
|
||||
@ -35,9 +36,17 @@ func (database *Database) MakeProjectSnapshots() {
|
||||
extract(epoch from now() at time zone 'utc')
|
||||
FROM project`)
|
||||
handleErr(err)
|
||||
inserted, _ := insertRes.RowsAffected()
|
||||
|
||||
res, err := db.Exec(`DELETE FROM project_monitoring_snapshot WHERE timestamp < $1`,
|
||||
int64(time.Now().Unix())-int64(config.Cfg.MonitoringHistory.Seconds()))
|
||||
handleErr(err)
|
||||
deleted, _ := res.RowsAffected()
|
||||
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"took": time.Now().Sub(startTime),
|
||||
"took": time.Now().Sub(startTime),
|
||||
"add": inserted,
|
||||
"remove": deleted,
|
||||
}).Trace("Took monitoring snapshot")
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,3 @@
|
||||
mat-divider {
|
||||
margin: 1em 0 !important;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
<div class="container">
|
||||
<mat-card class="mat-elevation-z8" *ngIf="account">
|
||||
<mat-card class="mat-elevation-z8" *ngIf="authService.account">
|
||||
|
||||
<mat-card-header>
|
||||
<mat-card-title>{{"account.title" | translate}}</mat-card-title>
|
||||
@ -11,19 +11,22 @@
|
||||
<mat-list>
|
||||
<mat-list-item>
|
||||
{{"account.username" | translate}}:
|
||||
<pre>{{account.username}}</pre>
|
||||
<pre>{{authService.account.username}}</pre>
|
||||
</mat-list-item>
|
||||
</mat-list>
|
||||
|
||||
<mat-expansion-panel>
|
||||
<mat-expansion-panel-header>{{"account.metadata" | translate}}</mat-expansion-panel-header>
|
||||
<pre> {{account | json}}</pre>
|
||||
<pre> {{authService.account | json}}</pre>
|
||||
</mat-expansion-panel>
|
||||
|
||||
<mat-divider class="divider" [inset]="true"></mat-divider>
|
||||
|
||||
</mat-card-content>
|
||||
|
||||
<mat-card-actions>
|
||||
|
||||
|
||||
<button mat-raised-button color="primary" (click)="logout()">{{"account.logout" | translate}}</button>
|
||||
</mat-card-actions>
|
||||
</mat-card>
|
||||
</div>
|
||||
|
||||
|
@ -8,13 +8,13 @@ import {AuthService} from "../auth.service";
|
||||
})
|
||||
export class AccountDetailsComponent implements OnInit {
|
||||
|
||||
account: Manager;
|
||||
|
||||
constructor(private authService: AuthService) {
|
||||
constructor(public authService: AuthService) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.account = this.authService.account;
|
||||
}
|
||||
|
||||
public logout() {
|
||||
this.authService.logout();
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,10 @@ export class ApiService {
|
||||
return this.http.post(this.url + "/login", credentials, this.options)
|
||||
}
|
||||
|
||||
logout() {
|
||||
return this.http.get(this.url + "/logout", this.options)
|
||||
}
|
||||
|
||||
getAccountDetails() {
|
||||
return this.http.get(this.url + "/account", this.options)
|
||||
}
|
||||
|
@ -29,8 +29,12 @@
|
||||
</mat-menu>
|
||||
</div>
|
||||
<span class="nav-spacer"></span>
|
||||
<button mat-button [class.mat-accent]="router.url == '/login'" class="nav-link"
|
||||
<button mat-button [class.mat-accent]="router.url == '/login'"
|
||||
class="nav-link" *ngIf="!authService.account"
|
||||
[routerLink]="'login'">{{"nav.login" | translate}}</button>
|
||||
<button mat-button [class.mat-accent]="router.url == '/account'"
|
||||
class="nav-link" *ngIf="authService.account"
|
||||
[routerLink]="'account'">{{"nav.account" | translate}}</button>
|
||||
|
||||
<button mat-button [matMenuTriggerFor]="langMenu">
|
||||
{{"nav.lang_select" | translate}}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import {Component} from '@angular/core';
|
||||
import {Router} from '@angular/router';
|
||||
import {TranslateService} from "@ngx-translate/core";
|
||||
import {AuthService} from "./auth.service";
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
@ -18,7 +19,9 @@ export class AppComponent {
|
||||
{lang: "en", display: "English"},
|
||||
];
|
||||
|
||||
constructor(private translate: TranslateService, private router: Router) {
|
||||
constructor(private translate: TranslateService,
|
||||
private router: Router,
|
||||
public authService: AuthService) {
|
||||
|
||||
translate.addLangs([
|
||||
"en",
|
||||
|
@ -14,6 +14,10 @@ export class AuthService {
|
||||
constructor(private apiService: ApiService,
|
||||
private messengerService: MessengerService,
|
||||
private router: Router) {
|
||||
this.apiService.getAccountDetails()
|
||||
.subscribe((data: any) => {
|
||||
this.account = data.manager;
|
||||
})
|
||||
}
|
||||
|
||||
public login(credentials: Credentials) {
|
||||
@ -33,6 +37,20 @@ export class AuthService {
|
||||
)
|
||||
}
|
||||
|
||||
public logout() {
|
||||
return this.apiService.logout()
|
||||
.subscribe(
|
||||
() => {
|
||||
this.account = null;
|
||||
this.router.navigateByUrl("");
|
||||
},
|
||||
error => {
|
||||
console.log(error);
|
||||
this.messengerService.show(error.error.message);
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
public register(credentials: Credentials) {
|
||||
return this.apiService.register(credentials)
|
||||
.subscribe(() =>
|
||||
|
@ -6,7 +6,8 @@
|
||||
"project_list": "Projects",
|
||||
"new_project": "New Project",
|
||||
"login": "Login",
|
||||
"worker_dashboard": "Workers"
|
||||
"worker_dashboard": "Workers",
|
||||
"account": "Account"
|
||||
},
|
||||
"logs": {
|
||||
"filter": "Filter",
|
||||
@ -79,7 +80,8 @@
|
||||
"metadata": "Account metadata",
|
||||
"title": "Account details",
|
||||
"subtitle": "toto: subtitle",
|
||||
"username": "Username"
|
||||
"username": "Username",
|
||||
"logout": "Logout"
|
||||
},
|
||||
"workers": {
|
||||
"title": "Completed tasks per worker",
|
||||
|
@ -6,7 +6,8 @@
|
||||
"project_list": "Projets",
|
||||
"new_project": "Nouveau projet",
|
||||
"login": "Ouvrir un session",
|
||||
"worker_dashboard": "Workers"
|
||||
"worker_dashboard": "Workers",
|
||||
"account": "Compte"
|
||||
},
|
||||
"logs": {
|
||||
"filter": "Filtrer",
|
||||
@ -81,7 +82,8 @@
|
||||
"metadata": "Métadonnés du compte",
|
||||
"title": "Détails du compte",
|
||||
"subtitle": "toto: sous-titre",
|
||||
"username": "Nom d'utilisateur"
|
||||
"username": "Nom d'utilisateur",
|
||||
"logout": "Fermer la session"
|
||||
},
|
||||
"workers": {
|
||||
"title": "Tâches complétés par worker",
|
||||
|
Loading…
x
Reference in New Issue
Block a user