Update storage queues and remote server info
This commit is contained in:
parent
fff753e3aa
commit
8f75009848
4 changed files with 110 additions and 14 deletions
|
@ -1,8 +1,6 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
|
@ -23,8 +21,7 @@ const (
|
|||
// Ensures data consistency in case the server is forced to restart unexpectedly
|
||||
// No DeletedAt field since don't want completed jobs to linger in the db for any longer than necessary
|
||||
type InboundJob struct {
|
||||
ID uint `gorm:"primarykey"`
|
||||
CreatedAt time.Time
|
||||
gorm.Model
|
||||
// Raw data, could be json or gob data, check source for how to interpret
|
||||
RawData []byte `gorm:"->;<-create"`
|
||||
// Where this job is coming from. Important for figuring out how to decode the raw data and what to do with it
|
||||
|
@ -47,9 +44,9 @@ func (s *Storage) AddNewInboundJob(data []byte, source InboundJobSource, inboxOw
|
|||
}
|
||||
|
||||
// Get the specified amount of jobs, sorted by age (oldest first)
|
||||
func (s *Storage) GetOldestInboundJobs(amount int) ([]InboundJob, error) {
|
||||
func (s *Storage) GetOldestInboundJobs(amount uint) ([]InboundJob, error) {
|
||||
jobs := []InboundJob{}
|
||||
switch err := s.db.Order("id asc, created_at asc").Limit(amount).Find(jobs).Error; err {
|
||||
switch err := s.db.Order("id asc, created_at asc").Limit(int(amount)).Find(jobs).Error; err {
|
||||
case gorm.ErrRecordNotFound:
|
||||
return nil, ErrEntryNotFound
|
||||
case nil:
|
||||
|
@ -58,3 +55,8 @@ func (s *Storage) GetOldestInboundJobs(amount int) ([]InboundJob, error) {
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Storage) CompleteInboundJob(id uint) error {
|
||||
s.db.Delete(InboundJob{Model: gorm.Model{ID: id}})
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue