Skip to content
Snippets Groups Projects
Commit 4f036d0a authored by Christian Pointner's avatar Christian Pointner
Browse files

removed usless success flag in import state

parent f8874952
No related branches found
No related tags found
No related merge requests found
......@@ -74,7 +74,7 @@ func (job *Job) run() error {
job.prepareSource()
if !atomic.CompareAndSwapUint32((*uint32)(&job.State), uint32(JobPending), uint32(JobRunning)) {
job.im.store.UpdateFileImportState(job.Group, job.ID, store.ImportAborted, false)
job.im.store.UpdateFileImportState(job.Group, job.ID, store.ImportAborted)
// the job was canceled before job.Start() could initialize the context and because of this
// job.Cancel() only set the state to JobCanceled... so we simulate a canceled context here
return context.Canceled
......@@ -83,19 +83,19 @@ func (job *Job) run() error {
job.StartedAt.set(time.Now())
job.im.dbgLog.Printf("running import for %s/%d from: %s", job.Group, job.ID, job.Source.String())
job.im.store.UpdateFileImportState(job.Group, job.ID, store.ImportRunning, false)
job.im.store.UpdateFileImportState(job.Group, job.ID, store.ImportRunning)
loudness, err := job.fetch()
if err != nil {
job.im.store.UpdateFileImportState(job.Group, job.ID, store.ImportAborted, false)
job.im.store.UpdateFileImportState(job.Group, job.ID, store.ImportAborted)
// send result to all done subscriptions
return err
}
if err = job.normalize(loudness); err != nil {
job.im.store.UpdateFileImportState(job.Group, job.ID, store.ImportAborted, false)
job.im.store.UpdateFileImportState(job.Group, job.ID, store.ImportAborted)
// send result to all done subscriptions
return err
}
job.im.store.UpdateFileImportState(job.Group, job.ID, store.ImportDone, true)
job.im.store.UpdateFileImportState(job.Group, job.ID, store.ImportDone)
// send result to all done subscriptions
return err
}
......@@ -132,7 +132,7 @@ func (job *Job) Start(ctx context.Context, timeout time.Duration) (err error) {
// although the job is not really enqueued yet we need to update the file state here because after the
// select there is a race between this update call and the one performed in the beginning of job.run()
job.im.store.UpdateFileImportState(job.Group, job.ID, store.ImportPending, false)
job.im.store.UpdateFileImportState(job.Group, job.ID, store.ImportPending)
select {
case job.im.work <- job:
if !atomic.CompareAndSwapUint32((*uint32)(&job.State), uint32(JobInitializing), uint32(JobPending)) {
......@@ -144,7 +144,7 @@ func (job *Job) Start(ctx context.Context, timeout time.Duration) (err error) {
}
default:
// the work channel is already full so we need to drop all new jobs...
job.im.store.UpdateFileImportState(job.Group, job.ID, store.ImportAborted, false)
job.im.store.UpdateFileImportState(job.Group, job.ID, store.ImportAborted)
job.cancel()
job.cleanup()
return ErrTooManyJobs
......
......@@ -83,7 +83,7 @@ func (st *Store) UpdateFileMetadata(group string, id uint64, metadata map[string
tx.Rollback()
return nil, err
}
if file.Source.Import.State != ImportDone || !file.Source.Import.Success {
if file.Source.Import.State != ImportDone {
tx.Rollback()
return nil, ErrFileImportNotDone
}
......@@ -102,12 +102,11 @@ func (st *Store) UpdateFileMetadata(group string, id uint64, metadata map[string
return file, nil
}
func (st *Store) UpdateFileImportState(group string, id uint64, state ImportState, success bool) (*File, error) {
func (st *Store) UpdateFileImportState(group string, id uint64, state ImportState) (*File, error) {
file := &File{ID: id}
fields := make(map[string]interface{})
fields["source__import__state"] = state
fields["source__import__success"] = success
if state == ImportDone && success {
if state == ImportDone {
if err := st.populateFileMetadataFields(group, id, fields); err != nil {
return nil, err
}
......
......@@ -49,7 +49,7 @@ const (
var (
ErrNotImplemented = errors.New("not implemented")
ErrNotFound = gorm.ErrRecordNotFound
ErrFileImportNotDone = errors.New("file import is not yet done")
ErrFileImportNotDone = errors.New("file import is not done")
)
type ErrFileInUse struct {
......@@ -141,8 +141,7 @@ func (s *ImportState) UnmarshalText(data []byte) (err error) {
// }
type Import struct {
State ImportState `json:"state"`
Success bool `json:"success"`
State ImportState `json:"state"`
// Log ImportLog `json:"log"`
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment