update timed out jobs

This commit is contained in:
shoopea 2019-08-24 13:32:55 +08:00
parent bb14f6a1cf
commit 0d50ea9ed4
2 changed files with 31 additions and 26 deletions

10
job.go
View File

@ -770,35 +770,35 @@ func jobGDeposit(j Job) {
if res { if res {
log.Printf("jobGDeposit : Sending res.\n") log.Printf("jobGDeposit : Sending res.\n")
clientSendCWMsgDelay(p.ChatID64, `📦Resources`, delay) clientSendCWMsgDelay(p.ChatID64, `📦Resources`, delay)
err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, 10*time.Second) err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, (10+delay)*time.Second)
logOnError(err, "jobGDeposit : createJobCallback") logOnError(err, "jobGDeposit : createJobCallback")
delay = delay + 2 delay = delay + 2
} }
if alch { if alch {
log.Printf("jobGDeposit : Sending alch.\n") log.Printf("jobGDeposit : Sending alch.\n")
clientSendCWMsgDelay(p.ChatID64, `Alchemy`, delay) clientSendCWMsgDelay(p.ChatID64, `Alchemy`, delay)
err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, 10*time.Second) err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, (10+delay)*time.Second)
logOnError(err, "jobGDeposit : createJobCallback") logOnError(err, "jobGDeposit : createJobCallback")
delay = delay + 2 delay = delay + 2
} }
if misc { if misc {
log.Printf("jobGDeposit : Sending misc.\n") log.Printf("jobGDeposit : Sending misc.\n")
clientSendCWMsgDelay(p.ChatID64, `🗃Misc`, delay) clientSendCWMsgDelay(p.ChatID64, `🗃Misc`, delay)
err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, 10*time.Second) err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, (10+delay)*time.Second)
logOnError(err, "jobGDeposit : createJobCallback") logOnError(err, "jobGDeposit : createJobCallback")
delay = delay + 2 delay = delay + 2
} }
if craft { if craft {
log.Printf("jobGDeposit : Sending craft.\n") log.Printf("jobGDeposit : Sending craft.\n")
clientSendCWMsgDelay(p.ChatID64, `⚒Crafting`, delay) clientSendCWMsgDelay(p.ChatID64, `⚒Crafting`, delay)
err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, 10*time.Second) err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, (10+delay)*time.Second)
logOnError(err, "jobGDeposit : createJobCallback") logOnError(err, "jobGDeposit : createJobCallback")
delay = delay + 2 delay = delay + 2
} }
if equip { if equip {
log.Printf("jobGDeposit : Sending equip.\n") log.Printf("jobGDeposit : Sending equip.\n")
clientSendCWMsgDelay(p.ChatID64, `🏷Equipment`, delay) clientSendCWMsgDelay(p.ChatID64, `🏷Equipment`, delay)
err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, 10*time.Second) err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, (10+delay)*time.Second)
logOnError(err, "jobGDeposit : createJobCallback") logOnError(err, "jobGDeposit : createJobCallback")
delay = delay + 2 delay = delay + 2
} }

View File

@ -514,27 +514,32 @@ func JobWorker(id int, jobs <-chan Job) {
// FIXME : discard timed out jobs // FIXME : discard timed out jobs
for j := range jobs { for j := range jobs {
//log.Printf("JobWorker[%d] : Starting job %d.\n", id, j.ID64) //log.Printf("JobWorker[%d] : Starting job %d.\n", id, j.ID64)
switch j.JobTypeID { if time.Now().UTC().Before(j.Timeout) {
case objSubTypeJobRescanMsg: switch j.JobTypeID {
jobRescan(j) case objSubTypeJobRescanMsg:
case objSubTypeJobSetJobDone: jobRescan(j)
jobSetDone(j) case objSubTypeJobSetJobDone:
case objSubTypeJobPillage: jobSetDone(j)
jobPillage(j) case objSubTypeJobPillage:
case objSubTypeJobMsgClient: jobPillage(j)
jobMsgClient(j) case objSubTypeJobMsgClient:
case objSubTypeJobMsgRefresh: jobMsgClient(j)
jobMsgRefresh(j) case objSubTypeJobMsgRefresh:
case objSubTypeJobBackupExport: jobMsgRefresh(j)
jobBackupExport(j) case objSubTypeJobBackupExport:
case objSubTypeJobBackupImport: jobBackupExport(j)
jobBackupImport(j) case objSubTypeJobBackupImport:
case objSubTypeJobGStock: jobBackupImport(j)
jobGStock(j) case objSubTypeJobGStock:
case objSubTypeJobGDeposit: jobGStock(j)
jobGDeposit(j) case objSubTypeJobGDeposit:
default: jobGDeposit(j)
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID) default:
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID)
}
} else {
log.Printf("JobWorker[%d] : Job %d timed out.\n", id, j.ID64)
setJobDone(j.ID64)
} }
} }
log.Printf("jobWorker[" + strconv.Itoa(id) + "] : Closing.") log.Printf("jobWorker[" + strconv.Itoa(id) + "] : Closing.")