Fix report downloads deleting pending updates

This commit is contained in:
Vladimir Stoilov 2023-03-10 16:42:04 +01:00
parent d6687ecbad
commit c9d77682f8
4 changed files with 21 additions and 11 deletions

View file

@ -290,7 +290,7 @@ func (api *DatabaseAPI) handleGet(opID []byte, key string) {
r, err := api.db.Get(key)
if err == nil {
data, err = marshalRecord(r, true)
data, err = MarshalRecord(r, true)
}
if err != nil {
api.send(opID, dbMsgTypeError, err.Error(), nil)
@ -348,7 +348,7 @@ func (api *DatabaseAPI) processQuery(opID []byte, q *query.Query) (ok bool) {
// process query feed
if r != nil {
// process record
data, err := marshalRecord(r, true)
data, err := MarshalRecord(r, true)
if err != nil {
api.send(opID, dbMsgTypeWarning, err.Error(), nil)
continue
@ -425,7 +425,7 @@ func (api *DatabaseAPI) processSub(opID []byte, sub *database.Subscription) {
// process sub feed
if r != nil {
// process record
data, err := marshalRecord(r, true)
data, err := MarshalRecord(r, true)
if err != nil {
api.send(opID, dbMsgTypeWarning, err.Error(), nil)
continue
@ -629,9 +629,9 @@ func (api *DatabaseAPI) handleDelete(opID []byte, key string) {
api.send(opID, dbMsgTypeSuccess, emptyString, nil)
}
// marsharlRecords locks and marshals the given record, additionally adding
// MarshalRecords locks and marshals the given record, additionally adding
// metadata and returning it as json.
func marshalRecord(r record.Record, withDSDIdentifier bool) ([]byte, error) {
func MarshalRecord(r record.Record, withDSDIdentifier bool) ([]byte, error) {
r.Lock()
defer r.Unlock()

View file

@ -452,7 +452,7 @@ func (e *Endpoint) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var rec record.Record
rec, err = e.RecordFunc(apiRequest)
if err == nil && r != nil {
responseData, err = marshalRecord(rec, false)
responseData, err = MarshalRecord(rec, false)
}
case e.HandlerFunc != nil:

View file

@ -93,7 +93,7 @@ func (rv *ResourceVersion) String() string {
return rv.VersionNumber
}
// SemVer returns the semantiv version of the resource.
// SemVer returns the semantic version of the resource.
func (rv *ResourceVersion) SemVer() *semver.Version {
return rv.semVer
}

View file

@ -13,7 +13,7 @@ const (
StateFetching = "fetching" // Fetching a single file.
)
// RegistryState describtes the registry state.
// RegistryState describes the registry state.
type RegistryState struct {
sync.Mutex
reg *ResourceRegistry
@ -58,7 +58,7 @@ type UpdateState struct {
LastDownloadAt *time.Time
// LastDownloadError holds the error of the last download.
LastDownloadError error
// LastDownload holds the resources that we downloaded the last time udpates
// LastDownload holds the resources that we downloaded the last time updates
// were downloaded.
LastDownload []string
@ -145,8 +145,18 @@ func (s *RegistryState) ReportDownloads(downloaded []string, failed error) {
s.Updates.LastDownloadError = failed
s.Updates.LastDownload = downloaded
// Reset pending downloads, as they have now been downloaded.
s.Updates.PendingDownload = nil
// Remote downloaded resources from the pending list.
var newPendingDownload []string
outer:
for _, pend := range s.Updates.PendingDownload {
for _, down := range downloaded {
if pend == down {
continue outer
}
}
newPendingDownload = append(newPendingDownload, pend)
}
s.Updates.PendingDownload = newPendingDownload
if failed == nil {
s.Updates.LastSuccessAt = &now