update job shops
This commit is contained in:
parent
6ba48248e9
commit
4473b69002
49
bot.go
49
bot.go
@ -774,8 +774,8 @@ func botGStock(m *ChatWarsMessage) {
|
|||||||
|
|
||||||
func botShops(m *ChatWarsMessage) {
|
func botShops(m *ChatWarsMessage) {
|
||||||
// fan out to all active and non idle clients
|
// fan out to all active and non idle clients
|
||||||
/*
|
|
||||||
clts, err := getLockedAllIdleClient()
|
clts, err := getAllIdleClientID64()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
Type: commandReplyMsg,
|
Type: commandReplyMsg,
|
||||||
@ -786,44 +786,41 @@ func botShops(m *ChatWarsMessage) {
|
|||||||
TGCmdQueue <- c
|
TGCmdQueue <- c
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userID64 := clt.TGUserID64
|
|
||||||
clt.Mux.Unlock()
|
|
||||||
|
|
||||||
p := JobPayloadGStock{
|
j := JobPayloadShops{
|
||||||
MsgID64: m.ID64,
|
|
||||||
ChatID64: m.ChatID64,
|
|
||||||
Status: 0,
|
Status: 0,
|
||||||
|
ChatID64: m.ChatID64,
|
||||||
|
MsgID64: m.ID64,
|
||||||
}
|
}
|
||||||
b, _ := json.Marshal(p)
|
b, err := json.Marshal(j)
|
||||||
t := time.Now().UTC().Add(1 * time.Second)
|
logOnError(err, "botShops : Marshal")
|
||||||
_, err = createJob(cacheObjSubType[`job_gstock`], objJobPriority, userID64, 0, t, b)
|
jobID64, err := createJob(cacheObjSubType[`job_shops`], objJobPriority, clts[0], 0, time.Unix(maxUnixTimestamp, 0).UTC(), b)
|
||||||
|
|
||||||
if err != nil {
|
for i, id := range clts {
|
||||||
c := TGCommand{
|
j2 := JobPayloadShopsSlave{
|
||||||
Type: commandReplyMsg,
|
JobCallbackID64: jobID64,
|
||||||
Text: fmt.Sprintf("%s", err),
|
Status: 0,
|
||||||
FromMsgID64: m.ID64,
|
Slaves: len(clts),
|
||||||
FromChatID64: m.ChatID64,
|
Shops: make([]string, 0),
|
||||||
}
|
}
|
||||||
TGCmdQueue <- c
|
for j, link := range cfg.Bot.Shops {
|
||||||
} else {
|
if (j / len(clts)) == i {
|
||||||
c := TGCommand{
|
j2.Shops = append(j2.Shops, link)
|
||||||
Type: commandReplyMsg,
|
|
||||||
Text: "Stock requested",
|
|
||||||
FromMsgID64: m.ID64,
|
|
||||||
FromChatID64: m.ChatID64,
|
|
||||||
}
|
}
|
||||||
TGCmdQueue <- c
|
|
||||||
}
|
}
|
||||||
*/
|
b, err = json.Marshal(j2)
|
||||||
|
logOnError(err, "botShops : Marshal Slave")
|
||||||
|
_, err = createJob(cacheObjSubType[`job_shops_slave`], objJobPriority, id, 0, time.Now().UTC(), b)
|
||||||
|
}
|
||||||
|
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
Type: commandReplyMsg,
|
Type: commandReplyMsg,
|
||||||
Text: "Not implemented",
|
Text: "Shops coming",
|
||||||
FromMsgID64: m.ID64,
|
FromMsgID64: m.ID64,
|
||||||
FromChatID64: m.ChatID64,
|
FromChatID64: m.ChatID64,
|
||||||
}
|
}
|
||||||
TGCmdQueue <- c
|
TGCmdQueue <- c
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
31
client.go
31
client.go
@ -114,9 +114,7 @@ func setClientIdle(userID64 int64, from time.Time) error {
|
|||||||
clt.CWBusyUntil = from
|
clt.CWBusyUntil = from
|
||||||
clt.GameIdle = true
|
clt.GameIdle = true
|
||||||
clt.CWLastUpdate = from
|
clt.CWLastUpdate = from
|
||||||
log.Printf("setClientIdle[%s] : updated.\n", clt.Login)
|
|
||||||
} else {
|
} else {
|
||||||
log.Printf("setClientIdle[%s] : not updated.\n", clt.Login)
|
|
||||||
}
|
}
|
||||||
clt.Mux.Unlock()
|
clt.Mux.Unlock()
|
||||||
return nil
|
return nil
|
||||||
@ -131,7 +129,6 @@ func getLockedIdleClient() (*ChirpClient, error) {
|
|||||||
for _, c := range clients {
|
for _, c := range clients {
|
||||||
if c.GameIdle {
|
if c.GameIdle {
|
||||||
ids = append(ids, c.TGUserID64)
|
ids = append(ids, c.TGUserID64)
|
||||||
fmt.Printf("getLockedIdleClient : appending %s (%d).\n", c.Login, c.TGUserID64)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
muxClients.RUnlock()
|
muxClients.RUnlock()
|
||||||
@ -141,7 +138,6 @@ func getLockedIdleClient() (*ChirpClient, error) {
|
|||||||
|
|
||||||
RndMux.Lock()
|
RndMux.Lock()
|
||||||
id := RndSrc.Intn(len(ids))
|
id := RndSrc.Intn(len(ids))
|
||||||
fmt.Printf("getLockedIdleClient : pulled %s.\n", clients[ids[id]].Login)
|
|
||||||
RndMux.Unlock()
|
RndMux.Unlock()
|
||||||
|
|
||||||
clients[ids[id]].Mux.Lock()
|
clients[ids[id]].Mux.Lock()
|
||||||
@ -150,6 +146,33 @@ func getLockedIdleClient() (*ChirpClient, error) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getLockedAllIdleClientID64() ([]int64, error) {
|
||||||
|
muxClients.RLock()
|
||||||
|
ids := make([]int64, 0)
|
||||||
|
for _, c := range clients {
|
||||||
|
if c.GameIdle {
|
||||||
|
ids = append(ids, c.TGUserID64)
|
||||||
|
clients[ids[id]].Mux.Lock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
muxClients.RUnlock()
|
||||||
|
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAllIdleClientID64() ([]int64, error) {
|
||||||
|
muxClients.RLock()
|
||||||
|
ids := make([]int64, 0)
|
||||||
|
for _, c := range clients {
|
||||||
|
if c.GameIdle {
|
||||||
|
ids = append(ids, c.TGUserID64)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
muxClients.RUnlock()
|
||||||
|
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
func getLockedClient(id int64, createMissing bool) (*ChirpClient, bool) {
|
func getLockedClient(id int64, createMissing bool) (*ChirpClient, bool) {
|
||||||
muxClients.RLock()
|
muxClients.RLock()
|
||||||
if c, ok := clients[id]; ok {
|
if c, ok := clients[id]; ok {
|
||||||
|
@ -769,6 +769,11 @@
|
|||||||
"name": "Shops summary job",
|
"name": "Shops summary job",
|
||||||
"obj_type": "job"
|
"obj_type": "job"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"intl_id": "job_shops_slave",
|
||||||
|
"name": "Shops summary slave job",
|
||||||
|
"obj_type": "job"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"intl_id": "job_check_vault_limit",
|
"intl_id": "job_check_vault_limit",
|
||||||
"name": "Check vault resource limit",
|
"name": "Check vault resource limit",
|
||||||
|
15
def.go
15
def.go
@ -557,6 +557,21 @@ type JobPayloadGetVault struct {
|
|||||||
CleanupMsg []ChatWarsMessage `json:"cleanup_msg"`
|
CleanupMsg []ChatWarsMessage `json:"cleanup_msg"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type JobPayloadShops struct {
|
||||||
|
MsgID64 int64 `json:"msg_id"`
|
||||||
|
ChatID64 int64 `json:"chat_id"`
|
||||||
|
Status int64 `json:"status"`
|
||||||
|
ShopMainAckMsg []ChatWarsMessage `json:"shop_main_ack_msg"`
|
||||||
|
CleanupMsg []ChatWarsMessage `json:"cleanup_msg"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type JobPayloadShopsSlave struct {
|
||||||
|
Status int64 `json:"status"`
|
||||||
|
JobCallbackID64 int64 `json:"job_callback_id"`
|
||||||
|
Shops []string `json:"shops"`
|
||||||
|
Slaves int64 `json:"slaves"`
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
userID64ChtWrsBot = 408101137
|
userID64ChtWrsBot = 408101137
|
||||||
|
|
||||||
|
16
job.go
16
job.go
@ -2179,6 +2179,22 @@ func jobCheckVaultLimit(j Job) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func jobShops(j Job) {
|
||||||
|
|
||||||
|
err = setJobDone(j.ID64)
|
||||||
|
logOnError(err, "jobShops : setJobDone")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func jobShopsSlave(j Job) {
|
||||||
|
|
||||||
|
err = setJobDone(j.ID64)
|
||||||
|
logOnError(err, "jobShopsSlave : setJobDone")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func jobGetVault(j Job) {
|
func jobGetVault(j Job) {
|
||||||
var (
|
var (
|
||||||
p JobPayloadGetVault
|
p JobPayloadGetVault
|
||||||
|
@ -633,6 +633,10 @@ func JobWorker(id int, jobs <-chan Job) {
|
|||||||
jobCraftAll(j)
|
jobCraftAll(j)
|
||||||
case cacheObjSubType[`job_check_vault_limit`]:
|
case cacheObjSubType[`job_check_vault_limit`]:
|
||||||
jobCheckVaultLimit(j)
|
jobCheckVaultLimit(j)
|
||||||
|
case cacheObjSubType[`job_shops`]:
|
||||||
|
jobShops(j)
|
||||||
|
case cacheObjSubType[`job_shops_slave`]:
|
||||||
|
jobShopsSlave(j)
|
||||||
default:
|
default:
|
||||||
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID64)
|
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID64)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user