Crashes are now saved in the database

This commit is contained in:
2019-11-04 16:34:00 +09:00
parent 604dc3c755
commit 2e9ad4bf6f
11 changed files with 125 additions and 5 deletions

@ -14,7 +14,7 @@ type ClientErrorReport struct {
hasCreator
}
// StreamClientErrorReports returns a stream of all characters.
// StreamClientErrorReports returns a stream of all client error reports.
func StreamClientErrorReports() <-chan *ClientErrorReport {
channel := make(chan *ClientErrorReport, nano.ChannelBufferSize)
@ -29,10 +29,9 @@ func StreamClientErrorReports() <-chan *ClientErrorReport {
return channel
}
// AllClientErrorReports returns a slice of all characters.
// AllClientErrorReports returns a slice of all client error reports.
func AllClientErrorReports() []*ClientErrorReport {
all := make([]*ClientErrorReport, 0, DB.Collection("ClientErrorReport").Count())
stream := StreamClientErrorReports()
for obj := range stream {

@ -7,6 +7,7 @@ import (
"github.com/aerogo/api"
)
// Force interface implementations
var (
_ api.Newable = (*ClientErrorReport)(nil)
)

39
arn/Crash.go Normal file

@ -0,0 +1,39 @@
package arn
import "github.com/aerogo/nano"
// Crash contains data about server crashes.
type Crash struct {
Error string `json:"error"`
Stack string `json:"stack"`
hasID
hasCreator
}
// StreamCrashes returns a stream of all crashes.
func StreamCrashes() <-chan *Crash {
channel := make(chan *Crash, nano.ChannelBufferSize)
go func() {
for obj := range DB.All("Crash") {
channel <- obj.(*Crash)
}
close(channel)
}()
return channel
}
// AllCrashes returns a slice of all crashes.
func AllCrashes() []*Crash {
all := make([]*Crash, 0, DB.Collection("Crash").Count())
stream := StreamCrashes()
for obj := range stream {
all = append(all, obj)
}
return all
}

13
arn/CrashAPI.go Normal file

@ -0,0 +1,13 @@
package arn
import "github.com/aerogo/api"
// Force interface implementations
var (
_ api.Savable = (*Crash)(nil)
)
// Save saves the crash in the database.
func (crash *Crash) Save() {
DB.Set("Crash", crash.ID, crash)
}

@ -25,6 +25,7 @@ var DB = Node.Namespace("arn").RegisterTypes(
(*AnimeCharacters)(nil),
(*AnimeRelations)(nil),
(*AnimeList)(nil),
(*Crash)(nil),
(*Character)(nil),
(*ClientErrorReport)(nil),
(*Company)(nil),