This commit is contained in:
shoopea 2020-06-29 13:49:33 +02:00
parent 96e67caba5
commit fe8d55a267

26
job.go
View File

@ -2080,11 +2080,6 @@ func jobGetStash(j Job) {
err = json.Unmarshal(j.Payload, &p) err = json.Unmarshal(j.Payload, &p)
logOnError(err, "jobGetStash : Unmarshal payload") logOnError(err, "jobGetStash : Unmarshal payload")
fmt.Printf("jobGetStash : Start ..\n")
fmt.Printf("jobGetStash : Trigger : %d\n", j.Trigger)
fmt.Printf("jobGetStash : UserID64 : %d\n", p.UserID64)
fmt.Printf("jobGetStash : len(p.ClientID64) : %d\n", len(p.ClientID64))
if j.Trigger > 0 { if j.Trigger > 0 {
m, err := getObjMsg(j.Trigger) m, err := getObjMsg(j.Trigger)
logOnError(err, "jobGetStash : getObjMsg("+strconv.FormatInt(j.Trigger, 10)+")") logOnError(err, "jobGetStash : getObjMsg("+strconv.FormatInt(j.Trigger, 10)+")")
@ -2095,18 +2090,15 @@ func jobGetStash(j Job) {
p.CleanupMsg = append(p.CleanupMsg, *m) p.CleanupMsg = append(p.CleanupMsg, *m)
setJobPayloadJSON(j.ID64, p) setJobPayloadJSON(j.ID64, p)
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC()) rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
fmt.Printf("jobGetStash : delete exchange req for current client\n")
return return
} else if rule.MsgTypeID64 == cacheObjSubType[`msg_exchange_ack`] { } else if rule.MsgTypeID64 == cacheObjSubType[`msg_exchange_ack`] {
p.CleanupMsg = append(p.CleanupMsg, *m) p.CleanupMsg = append(p.CleanupMsg, *m)
fmt.Printf("jobGetStash : Ack received : deleting current client\n")
l := len(p.ClientID64) l := len(p.ClientID64)
for k, v := range p.ClientID64 { for k, v := range p.ClientID64 {
fmt.Printf("jobGetStash : testing client [%d/%d] : %d\n", k+1, l, v) fmt.Printf("jobGetStash : testing client [%d/%d] : %d\n", k+1, l, v)
if v == p.UserID64 { if v == p.UserID64 {
p.ClientID64[l-1], p.ClientID64[k] = p.ClientID64[k], p.ClientID64[l-1] p.ClientID64[l-1], p.ClientID64[k] = p.ClientID64[k], p.ClientID64[l-1]
p.ClientID64 = p.ClientID64[:l-1] p.ClientID64 = p.ClientID64[:l-1]
fmt.Printf("jobGetStash : client deleted\n")
break break
} }
} }
@ -2117,13 +2109,10 @@ func jobGetStash(j Job) {
p.Stash[d.ItemID64] += d.Quantity p.Stash[d.ItemID64] += d.Quantity
} }
} }
fmt.Printf("jobGetStash : %d clients remaining\n", len(p.ClientID64))
fmt.Printf("jobGetStash : clearing trigger for next client\n")
j.Trigger = 0 j.Trigger = 0
} else if rule.MsgTypeID64 == cacheObjSubType[`msg_busy`] { } else if rule.MsgTypeID64 == cacheObjSubType[`msg_busy`] {
p.CleanupMsg = append(p.CleanupMsg, *m) p.CleanupMsg = append(p.CleanupMsg, *m)
j.Trigger = 0 j.Trigger = 0
fmt.Printf("jobGetStash : client busy => clearing trigger for next client\n")
} }
} }
} }
@ -2145,7 +2134,6 @@ func jobGetStash(j Job) {
clt.Mux.Unlock() clt.Mux.Unlock()
} }
} }
fmt.Printf("jobGetStash : Submit new client : %d (%v)\n", userID64, busyUntil.Add(5*time.Second).Sub(time.Now().UTC()))
p.UserID64 = userID64 p.UserID64 = userID64
setJobCallback(j.ID64, userID64, cacheObjSubType[`msg_exchange_req`]) setJobCallback(j.ID64, userID64, cacheObjSubType[`msg_exchange_req`])
setJobCallback(j.ID64, userID64, cacheObjSubType[`msg_exchange_ack`]) setJobCallback(j.ID64, userID64, cacheObjSubType[`msg_exchange_ack`])
@ -2153,29 +2141,19 @@ func jobGetStash(j Job) {
setJobPayloadJSON(j.ID64, p) setJobPayloadJSON(j.ID64, p)
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC()) rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
clientSendCWMsgDelay(userID64, "⚖Exchange", busyUntil.Add(2*time.Second).Sub(time.Now().UTC())) clientSendCWMsgDelay(userID64, "⚖Exchange", busyUntil.Add(2*time.Second).Sub(time.Now().UTC()))
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("Client[%d/%d] : %d", (p.ClientCount - int64(len(p.ClientID64)) + 1), p.ClientCount, userID64),
FromMsgID64: p.MsgID64,
FromChatID64: p.ChatID64,
ParseMode: cmdParseModeHTML,
}
TGCmdQueue <- c
return return
} }
if len(p.ClientID64) == 0 && j.Trigger == 0 { if len(p.ClientID64) == 0 && j.Trigger == 0 {
fmt.Printf("jobGetStash : Cleaning up\n")
for _, m := range p.CleanupMsg { for _, m := range p.CleanupMsg {
fmt.Printf("jobGetStash : clientDelTGMsg(%d, %d, %d)\n", m.TGUserID64, m.ID64, m.ChatID64)
clientDelTGMsg(m.TGUserID64, m.ID64, m.ChatID64) clientDelTGMsg(m.TGUserID64, m.ID64, m.ChatID64)
} }
} }
out := "Stash:\n" out := "Stash:\n"
for k, v := range p.Stash { for k, v := range p.Stash {
out = fmt.Sprintf("%s %d : %d\n", out, k, v) i, _ := getObjItem(k)
out = fmt.Sprintf("%s %d : %d\n", out, i.Names[0], v)
} }
c := TGCommand{ c := TGCommand{