This commit is contained in:
Melody Becker 2024-09-16 17:42:16 +02:00
parent 1a97c35e22
commit 704d0e8750
4 changed files with 49 additions and 1 deletions

View file

@ -2,6 +2,8 @@ package storage
import (
"time"
"gorm.io/gorm"
)
// Auto-generate string names for the various constants
@ -34,3 +36,25 @@ type InboundJob struct {
// If from an inbox, include the owner id here
InboxOwner *string `gorm:"->;<-create"`
}
func (s *Storage) AddNewInboundJob(data []byte, source InboundJobSource, inboxOwner *string) {
newJob := InboundJob{
RawData: data,
Source: source,
InboxOwner: inboxOwner,
}
s.db.Create(&newJob)
}
// Get the specified amount of jobs, sorted by age (oldest first)
func (s *Storage) GetOldestInboundJobs(amount int) ([]InboundJob, error) {
jobs := []InboundJob{}
switch err := s.db.Order("id asc, created_at asc").Limit(amount).Find(jobs).Error; err {
case gorm.ErrRecordNotFound:
return nil, ErrEntryNotFound
case nil:
return jobs, nil
default:
return nil, err
}
}