FindDuplicate checks if another instance is already downloading the same element. Only considers records updated within the last 30 minutes as active — older in-progress records are assumed to be stale (crashed instance).
(elementName string)
| 173 | // Only considers records updated within the last 30 minutes as active — older |
| 174 | // in-progress records are assumed to be stale (crashed instance). |
| 175 | func (s *GalleryStore) FindDuplicate(elementName string) (*GalleryOperationRecord, error) { |
| 176 | var op GalleryOperationRecord |
| 177 | staleCutoff := time.Now().Add(-30 * time.Minute) |
| 178 | err := s.db.Where("gallery_element_name = ? AND status IN ? AND updated_at > ?", elementName, |
| 179 | activeStatuses, staleCutoff).First(&op).Error |
| 180 | if err != nil { |
| 181 | return nil, err |
| 182 | } |
| 183 | return &op, nil |
| 184 | } |
| 185 | |
| 186 | // Cancel marks an operation as cancelled. |
| 187 | func (s *GalleryStore) Cancel(id string) error { |
no test coverage detected