2022-10-31 15:28:29 +00:00
|
|
|
// Copyright (C) 2022 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package nodeevents
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"storj.io/common/storj"
|
|
|
|
"storj.io/common/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DB implements the database for node events.
|
|
|
|
//
|
|
|
|
// architecture: Database
|
|
|
|
type DB interface {
|
|
|
|
// Insert a node event into the node events table.
|
|
|
|
Insert(ctx context.Context, email string, nodeID storj.NodeID, event Type) (nodeEvent NodeEvent, err error)
|
|
|
|
// GetLatestByEmailAndEvent gets latest node event by email and event type.
|
|
|
|
GetLatestByEmailAndEvent(ctx context.Context, email string, event Type) (nodeEvent NodeEvent, err error)
|
2022-11-07 19:07:24 +00:00
|
|
|
// GetNextBatch gets the next batch of events to combine into an email.
|
|
|
|
GetNextBatch(ctx context.Context, firstSeenBefore time.Time) (events []NodeEvent, err error)
|
2022-11-18 21:58:08 +00:00
|
|
|
// GetByID get a node event by id.
|
|
|
|
GetByID(ctx context.Context, id uuid.UUID) (nodeEvent NodeEvent, err error)
|
2022-11-07 19:07:24 +00:00
|
|
|
// UpdateEmailSent updates email_sent for a group of rows.
|
|
|
|
UpdateEmailSent(ctx context.Context, ids []uuid.UUID, timestamp time.Time) (err error)
|
2022-11-18 22:18:30 +00:00
|
|
|
// UpdateLastAttempted updates last_attempted for a group of rows.
|
|
|
|
UpdateLastAttempted(ctx context.Context, ids []uuid.UUID, timestamp time.Time) (err error)
|
2022-10-31 15:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NodeEvent contains information needed to notify a node operator about something that happened to a node.
|
|
|
|
type NodeEvent struct {
|
2022-11-18 22:18:30 +00:00
|
|
|
ID uuid.UUID
|
|
|
|
Email string
|
|
|
|
NodeID storj.NodeID
|
|
|
|
Event Type
|
|
|
|
CreatedAt time.Time
|
|
|
|
LastAttempted *time.Time
|
|
|
|
EmailSent *time.Time
|
2022-10-31 15:28:29 +00:00
|
|
|
}
|