generated from telekom/reuse-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Refactoring and add some comments
- Loading branch information
1 parent
d1841e7
commit 818cfff
Showing
9 changed files
with
115 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,47 @@ | ||
package golaris | ||
|
||
import ( | ||
"eni.telekom.de/horizon2go/pkg/cache" | ||
"eni.telekom.de/horizon2go/pkg/enum" | ||
"eni.telekom.de/horizon2go/pkg/message" | ||
"eni.telekom.de/horizon2go/pkg/resource" | ||
"github.com/go-co-op/gocron" | ||
"github.com/hazelcast/hazelcast-go-client" | ||
"github.com/hazelcast/hazelcast-go-client/predicate" | ||
"github.com/rs/zerolog/log" | ||
"golaris/config" | ||
"golaris/utils" | ||
"time" | ||
) | ||
|
||
type SchedulerParams struct { | ||
cbCache *cache.Cache[message.CircuitBreakerMessage] | ||
subCache *cache.Cache[resource.SubscriptionResource] | ||
} | ||
|
||
var scheduler *gocron.Scheduler | ||
|
||
func InitializeScheduler(cbCache *cache.Cache[message.CircuitBreakerMessage], subCache *cache.Cache[resource.SubscriptionResource], healthCache *hazelcast.Map) { | ||
func InitializeScheduler(deps utils.Dependencies) { | ||
scheduler = gocron.NewScheduler(time.UTC) | ||
|
||
if _, err := scheduler.Every(config.Current.Polling.OpenCbMessageInterval).Do(func() { | ||
checkCircuitBreakersByStatus(cbCache, subCache, healthCache, enum.CircuitBreakerStatusOpen) | ||
checkCircuitBreakersByStatus(deps, enum.CircuitBreakerStatusOpen) | ||
}); err != nil { | ||
log.Error().Msgf("Error while scheduling for OPEN CircuitBreakers: %v", err) | ||
} | ||
|
||
//ToDo: With a scheduler or any other mechanism? | ||
//ToDo: When do we want to do this? Always or only on a pod restart? | ||
if _, err := scheduler.Every(config.Current.Polling.RepublishingOrCheckingMessageInterval).Do(func() { | ||
checkCircuitBreakersByStatus(cbCache, subCache, healthCache, enum.CircuitBreakerStatusRepublishing) | ||
checkCircuitBreakersByStatus(cbCache, subCache, healthCache, enum.CircuitBreakerStatusChecking) | ||
checkCircuitBreakersByStatus(deps, enum.CircuitBreakerStatusRepublishing) | ||
checkCircuitBreakersByStatus(deps, enum.CircuitBreakerStatusChecking) | ||
}); err != nil { | ||
log.Error().Msgf("Error while scheduling for REPUBLISHING and CHECKING CircuitBreakers: %v", err) | ||
} | ||
|
||
scheduler.StartAsync() | ||
} | ||
|
||
func checkCircuitBreakersByStatus(cbCache *cache.Cache[message.CircuitBreakerMessage], subCache *cache.Cache[resource.SubscriptionResource], healthCache *hazelcast.Map, status enum.CircuitBreakerStatus) { | ||
func checkCircuitBreakersByStatus(deps utils.Dependencies, status enum.CircuitBreakerStatus) { | ||
statusQuery := predicate.Equal("status", string(status)) | ||
cbEntries, err := cbCache.GetQuery(config.Current.Hazelcast.Caches.CircuitBreakerCache, statusQuery) | ||
cbEntries, err := deps.CbCache.GetQuery(config.Current.Hazelcast.Caches.CircuitBreakerCache, statusQuery) | ||
if err != nil { | ||
log.Debug().Msgf("Error while getting CircuitBreaker messages: %v", err) | ||
return | ||
} | ||
|
||
for _, entry := range cbEntries { | ||
log.Info().Msgf("Checking CircuitBreaker with id %s", entry.Status) | ||
go checkSubscriptionForCbMessage(subCache, healthCache, entry) | ||
go checkSubscriptionForCbMessage(deps, entry) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package golaris | ||
|
||
import ( | ||
"eni.telekom.de/horizon2go/pkg/message" | ||
"github.com/rs/zerolog/log" | ||
"golaris/config" | ||
"golaris/utils" | ||
) | ||
|
||
func checkSubscriptionForCbMessage(deps utils.Dependencies, cbMessage message.CircuitBreakerMessage) { | ||
subscriptionId := cbMessage.SubscriptionId | ||
|
||
subscription, err := deps.SubCache.Get(config.Current.Hazelcast.Caches.SubscriptionCache, subscriptionId) | ||
if err != nil { | ||
log.Error().Err(err).Msgf("Could not read subscription with id %s", subscriptionId) | ||
return | ||
} | ||
|
||
log.Info().Msgf("Subscription with id %s found: %v", subscriptionId, subscription) | ||
|
||
// ToDo: Check whether the subscription has changed | ||
|
||
go performHealthCheck(deps, subscription) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.