This commit is contained in:
shoopea 2020-06-19 22:48:55 +02:00
parent 33c3f44666
commit d66fe5482b

54
job.go
View File

@ -2080,6 +2080,60 @@ 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")
if j.Trigger > 0 {
m, err := getObjMsg(j.Trigger)
logOnError(err, "jobAlchAll : getObjMsg("+strconv.FormatInt(j.Trigger, 10)+")")
if err == nil {
rule, err := getMsgParsingRule(m)
logOnError(err, "jobAlchAll : getMsgParsingRule")
if rule.MsgTypeID64 == cacheObjSubType[`msg_exchange_req`] {
p.CleanupMsgs = append(p.CleanupMsg, *m)
setJobPayloadJSON(j.ID64, p)
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
return
} else if rule.MsgTypeID64 == cacheObjSubType[`msg_exchange_ack`] {
p.CleanupMsgs = append(p.CleanupMsg, *m)
for k, v := range p.ClientID64 {
if v == j.UserID64 {
p.ClientID64[len(p.ClientID64)-1], p.ClientID64[k] = p.ClientID64[k], p.ClientID64[len(p.ClientID64)-1]
p.ClientID64 = p.ClientID64[:len(p.ClientID64)-1]
}
}
p.Trigger = 0
} else if rule.MsgTypeID64 == cacheObjSubType[`msg_busy`] {
p.CleanupMsgs = append(p.CleanupMsg, *m)
}
}
}
if len(p.ClientID64) > 0 && p.Trigger == 0 {
var (
userID64 int64 = 0
busyUntil time.Time = time.Now().UTC()
)
for _, id := range p.ClientID64 {
clt, ok := getLockedClient(id, false)
if userID64 == 0 {
userID64 = clt.TGUserID64
busyUntil = clt.CWBusyUntil
} else if busyUntil.After(clt.CWBusyUntil) {
userID64 = clt.TGUserID64
busyUntil = clt.CWBusyUntil
}
}
setJobCallback(j.ID64, userID64, cacheObjSubType[`msg_exchange_req`])
setJobCallback(j.ID64, userID64, cacheObjSubType[`msg_exchange_ack`])
setJobCallback(j.ID64, userID64, cacheObjSubType[`msg_busy`])
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
clientSendCWMsgDelay(userID64, "⚖Exchange", time.Now().UTC().Add(-2*time.Second).Sub(busyUntil))
}
if len(p.ClientID64) == 0 && p.Trigger == 0 {
for _, m := range p.CleanupMsg {
clientDelTGMsg(m.TGUserID64, m.ID64, m.ChatID64)
}
}
err = setJobDone(j.ID64) err = setJobDone(j.ID64)
logOnError(err, "jobGetStash : setJobDone") logOnError(err, "jobGetStash : setJobDone")