mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
refactor: remove repeated code in readyPollTimer
This commit is contained in:
parent
7b0bbcefe6
commit
583ddcab7a
@ -48,7 +48,7 @@ func (w *WakatimeDumpImporter) Import(user *models.User, minFrom time.Time, maxT
|
|||||||
if err := json.NewDecoder(res.Body).Decode(&datadumpError); err != nil {
|
if err := json.NewDecoder(res.Body).Decode(&datadumpError); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if datadumpError.Error == "Wait for your current export to expire before creating another."{
|
if datadumpError.Error == "Wait for your current export to expire before creating another." {
|
||||||
dump_exist = true
|
dump_exist = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -162,22 +162,20 @@ func (w *WakatimeDumpImporter) Import(user *models.User, minFrom time.Time, maxT
|
|||||||
// start polling for dump to be ready
|
// start polling for dump to be ready
|
||||||
readyPollTimer, err = w.queue.DispatchEvery(func() {
|
readyPollTimer, err = w.queue.DispatchEvery(func() {
|
||||||
u := *user
|
u := *user
|
||||||
|
var ok bool
|
||||||
|
var dump *wakatime.DataDumpData
|
||||||
|
var err error
|
||||||
if dump_exist {
|
if dump_exist {
|
||||||
ok, dump, err := getLatestDump(&u)
|
ok, dump, err = getLatestDump(&u)
|
||||||
if err != nil {
|
|
||||||
onDumpFailed(err, &u)
|
|
||||||
} else if ok {
|
|
||||||
onDumpReady(dump, &u, out)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
ok, dump, err := checkDumpReady(datadumpData.Data.Id, &u)
|
ok, dump, err = checkDumpReady(datadumpData.Data.Id, &u)
|
||||||
logbuch.Info("waiting for data dump '%s' for user '%s' to become downloadable (%.2f percent complete)", datadumpData.Data.Id, u.ID, dump.PercentComplete)
|
}
|
||||||
|
logbuch.Info("waiting for data dump '%s' for user '%s' to become downloadable (%.2f percent complete)", dump.Id, u.ID, dump.PercentComplete)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
onDumpFailed(err, &u)
|
onDumpFailed(err, &u)
|
||||||
} else if ok {
|
} else if ok {
|
||||||
onDumpReady(dump, &u, out)
|
onDumpReady(dump, &u, out)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}, 10*time.Second)
|
}, 10*time.Second)
|
||||||
|
|
||||||
return out, nil
|
return out, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user