(channelId int, usingKey string, status int, reason string)
| 553 | } |
| 554 | |
| 555 | func UpdateChannelStatus(channelId int, usingKey string, status int, reason string) bool { |
| 556 | if common.MemoryCacheEnabled { |
| 557 | channelStatusLock.Lock() |
| 558 | defer channelStatusLock.Unlock() |
| 559 | |
| 560 | channelCache, _ := CacheGetChannel(channelId) |
| 561 | if channelCache == nil { |
| 562 | return false |
| 563 | } |
| 564 | if channelCache.ChannelInfo.IsMultiKey { |
| 565 | // 如果是多Key模式,更新缓存中的状态 |
| 566 | handlerMultiKeyUpdate(channelCache, usingKey, status) |
| 567 | //CacheUpdateChannel(channelCache) |
| 568 | //return true |
| 569 | } else { |
| 570 | // 如果缓存渠道存在,且状态已是目标状态,直接返回 |
| 571 | if channelCache.Status == status { |
| 572 | return false |
| 573 | } |
| 574 | // 如果缓存渠道不存在(说明已经被禁用),且要设置的状态不为启用,直接返回 |
| 575 | if status != common.ChannelStatusEnabled { |
| 576 | return false |
| 577 | } |
| 578 | CacheUpdateChannelStatus(channelId, status) |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | shouldUpdateAbilities := false |
| 583 | defer func() { |
| 584 | if shouldUpdateAbilities { |
| 585 | err := UpdateAbilityStatus(channelId, status == common.ChannelStatusEnabled) |
| 586 | if err != nil { |
| 587 | common.SysError("failed to update ability status: " + err.Error()) |
| 588 | } |
| 589 | } |
| 590 | }() |
| 591 | channel, err := GetChannelById(channelId, true) |
| 592 | if err != nil { |
| 593 | return false |
| 594 | } else { |
| 595 | if channel.Status == status { |
| 596 | return false |
| 597 | } |
| 598 | |
| 599 | if channel.ChannelInfo.IsMultiKey { |
| 600 | beforeStatus := channel.Status |
| 601 | handlerMultiKeyUpdate(channel, usingKey, status) |
| 602 | if beforeStatus != channel.Status { |
| 603 | shouldUpdateAbilities = true |
| 604 | } |
| 605 | } else { |
| 606 | info := channel.GetOtherInfo() |
| 607 | info["status_reason"] = reason |
| 608 | info["status_time"] = common.GetTimestamp() |
| 609 | channel.SetOtherInfo(info) |
| 610 | channel.Status = status |
| 611 | shouldUpdateAbilities = true |
| 612 | } |
no test coverage detected