Skip to content

Commit

Permalink
Merge pull request #247 from pixlise/feature/quant-logs
Browse files Browse the repository at this point in the history
Feature/quant logs
  • Loading branch information
pnemere authored Jun 27, 2024
2 parents 3a393ec + ddec459 commit b46c6e0
Show file tree
Hide file tree
Showing 9 changed files with 1,711 additions and 981 deletions.
4 changes: 3 additions & 1 deletion api/notificationSender/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ func (n *NotificationSender) sendNotification(sourceId string, topicId string, n
uiNotificationUsers = append(uiNotificationUsers, userId)
}

/* Removed because it's really not that helpful but spams logs heaps because lots of users don't have notifications on!
if method == protos.NotificationMethod_NOTIF_NONE {
n.log.Infof("Skipping notification of topic: %v to user %v because they have this topic turned off", topicId, userId)
n.log.Debugf("Skipping notification of topic: %v to user %v because they have this topic turned off", topicId, userId)
}
*/
}
}
}
Expand Down
85 changes: 85 additions & 0 deletions api/ws/handlers/quantification-retrieval.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/pixlise/core/v4/api/filepaths"
"github.com/pixlise/core/v4/api/quantification"
"github.com/pixlise/core/v4/api/ws/wsHelpers"
"github.com/pixlise/core/v4/core/errorwithstatus"
protos "github.com/pixlise/core/v4/generated-protos"
)

Expand All @@ -31,6 +32,10 @@ func HandleQuantListReq(req *protos.QuantListReq, hctx wsHelpers.HandlerContext)
}

func HandleQuantGetReq(req *protos.QuantGetReq, hctx wsHelpers.HandlerContext) (*protos.QuantGetResp, error) {
if err := wsHelpers.CheckStringField(&req.QuantId, "QuantId", 1, wsHelpers.IdFieldMaxLength); err != nil {
return nil, err
}

dbItem, ownerItem, err := wsHelpers.GetUserObjectById[protos.QuantificationSummary](false, req.QuantId, protos.ObjectType_OT_QUANTIFICATION, dbCollections.QuantificationsName, hctx)
if err != nil {
return nil, err
Expand Down Expand Up @@ -99,5 +104,85 @@ func HandleQuantLastOutputGetReq(req *protos.QuantLastOutputGetReq, hctx wsHelpe
}

return &protos.QuantLastOutputGetResp{Output: string(result)}, nil
}

func HandleQuantLogListReq(req *protos.QuantLogListReq, hctx wsHelpers.HandlerContext) (*protos.QuantLogListResp, error) {
if err := wsHelpers.CheckStringField(&req.QuantId, "QuantId", 1, wsHelpers.IdFieldMaxLength); err != nil {
return nil, err
}

// Check that user has access to this quant
dbItem, _, err := wsHelpers.GetUserObjectById[protos.QuantificationSummary](false, req.QuantId, protos.ObjectType_OT_QUANTIFICATION, dbCollections.QuantificationsName, hctx)
if err != nil {
return nil, err
}

logFilePaths, err := hctx.Svcs.FS.ListObjects(hctx.Svcs.Config.UsersBucket, path.Join(dbItem.Status.OutputFilePath, req.QuantId+"-logs")+"/")
if err != nil {
return nil, err
}

logFileNames := []string{}
for _, logpath := range logFilePaths {
logFileNames = append(logFileNames, path.Base(logpath))
}

return &protos.QuantLogListResp{
FileNames: logFileNames,
}, nil
}

func HandleQuantLogGetReq(req *protos.QuantLogGetReq, hctx wsHelpers.HandlerContext) (*protos.QuantLogGetResp, error) {
if err := wsHelpers.CheckStringField(&req.QuantId, "QuantId", 1, wsHelpers.IdFieldMaxLength); err != nil {
return nil, err
}
if err := wsHelpers.CheckStringField(&req.LogName, "LogName", 1, wsHelpers.IdFieldMaxLength); err != nil {
return nil, err
}

// Check that user has access to this quant
dbItem, _, err := wsHelpers.GetUserObjectById[protos.QuantificationSummary](false, req.QuantId, protos.ObjectType_OT_QUANTIFICATION, dbCollections.QuantificationsName, hctx)
if err != nil {
return nil, err
}

logPath := path.Join(dbItem.Status.OutputFilePath, req.QuantId+"-logs", req.LogName)
logData, err := hctx.Svcs.FS.ReadObject(hctx.Svcs.Config.UsersBucket, logPath)
if err != nil {
if hctx.Svcs.FS.IsNotFoundError(err) {
return nil, errorwithstatus.MakeNotFoundError(req.LogName)
}
return nil, err
}

return &protos.QuantLogGetResp{
LogData: string(logData),
}, nil
}

func HandleQuantRawDataGetReq(req *protos.QuantRawDataGetReq, hctx wsHelpers.HandlerContext) (*protos.QuantRawDataGetResp, error) {
if err := wsHelpers.CheckStringField(&req.QuantId, "QuantId", 1, wsHelpers.IdFieldMaxLength); err != nil {
return nil, err
}

// Check that user has access to this quant
dbItem, _, err := wsHelpers.GetUserObjectById[protos.QuantificationSummary](false, req.QuantId, protos.ObjectType_OT_QUANTIFICATION, dbCollections.QuantificationsName, hctx)
if err != nil {
return nil, err
}
//UserContent/5df311ed8a0b5d0ebf5fb476/089063943/Quantifications/
// Read the CSV file from S3

csvPath := path.Join(dbItem.Status.OutputFilePath, req.QuantId+".csv")
csvData, err := hctx.Svcs.FS.ReadObject(hctx.Svcs.Config.UsersBucket, csvPath)
if err != nil {
if hctx.Svcs.FS.IsNotFoundError(err) {
return nil, errorwithstatus.MakeNotFoundError(req.QuantId + ".csv")
}
return nil, err
}

return &protos.QuantRawDataGetResp{
Data: string(csvData),
}, nil
}
6 changes: 3 additions & 3 deletions api/ws/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ func (ws *WSHandler) HandleMessage(s *melody.Session, msg []byte) {
// Set incoming message ID on the outgoing one
resp.MsgId = wsmsg.MsgId

// Print out errors
if len(resp.ErrorText) > 0 {
fmt.Printf("Sending Response Error for msg id %v:\n %v\n", resp.MsgId-1, resp.ErrorText)
// Print out errors, except common ones (cache misses)
if len(resp.ErrorText) > 0 && resp.GetMemoiseGetResp() == nil {
fmt.Printf("Sending Response Error: %v\n", resp.String())
}

// Send
Expand Down
2 changes: 1 addition & 1 deletion data-formats
Loading

0 comments on commit b46c6e0

Please sign in to comment.