Skip to content

Commit

Permalink
fix service status
Browse files Browse the repository at this point in the history
  • Loading branch information
cryi committed Jul 27, 2024
1 parent eed295b commit 7a8951c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
5 changes: 5 additions & 0 deletions core/common/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import (

type ApplicationServices *map[string]base.AmiServiceInfo

type AplicationServicesStatus struct {
Applications map[string]ApplicationServices `json:"applications,omitempty"`
Timestamp int64 `json:"timestamp,omitempty"` // last update
}

type ServicesStatusUpdate struct {
Application string
Status ApplicationServices
Expand Down
22 changes: 15 additions & 7 deletions core/providers/tezbake/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,28 @@ package tezbake
import (
"context"
"maps"
"time"

"github.com/gofiber/fiber/v2"
"github.com/tez-capital/tezpeak/configuration"
"github.com/tez-capital/tezpeak/core/common"
)

type Status struct {
Rights RightsStatus `json:"rights,omitempty"`
Services map[string]common.ApplicationServices `json:"services,omitempty"`
Bakers BakersStatus `json:"bakers,omitempty"`
Ledgers LedgerStatus `json:"ledgers,omitempty"`
Rights RightsStatus `json:"rights,omitempty"`
Services common.AplicationServicesStatus `json:"services,omitempty"`
Bakers BakersStatus `json:"bakers,omitempty"`
Ledgers LedgerStatus `json:"ledgers,omitempty"`
}

func (status *Status) Clone() *Status {
return &Status{
// no need to clone RightsStatus
status.Rights,
maps.Clone(status.Services),
common.AplicationServicesStatus{
Applications: maps.Clone(status.Services.Applications),
Timestamp: status.Services.Timestamp,
},
status.Bakers, // no need to clone BakersStatus
status.Ledgers, // no need to clone LedgerStatus
}
Expand All @@ -32,7 +36,10 @@ func GetEmptyStatus() *Status {
Level: 0,
Rights: []*BlockRights{},
},
Services: make(map[string]common.ApplicationServices),
Services: common.AplicationServicesStatus{
Applications: make(map[string]common.ApplicationServices),
Timestamp: time.Now().Unix(),
},
Bakers: BakersStatus{
Level: 0,
Bakers: map[string]*BakerStakingStatus{},
Expand Down Expand Up @@ -73,7 +80,8 @@ func SetupModule(ctx context.Context, configuration *configuration.TezbakeModule
switch statusUpdate := statusUpdate.(type) {
case *common.ServicesStatusUpdate:
application := statusUpdate.Application
tezbakeStatus.Services[application] = statusUpdate.Status
tezbakeStatus.Services.Applications[application] = statusUpdate.Status
tezbakeStatus.Services.Timestamp = time.Now().Unix()
case *RightsStatusUpdate:
tezbakeStatus.Rights = statusUpdate.RightsStatus
case *BakersStatusUpdate:
Expand Down
20 changes: 14 additions & 6 deletions core/providers/tezpay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tezpay

import (
"context"
"time"

"github.com/gofiber/fiber/v2"
"github.com/tez-capital/tezpeak/configuration"
Expand All @@ -10,14 +11,17 @@ import (
)

type Status struct {
Services map[string]common.ApplicationServices `json:"services,omitempty"`
Wallet WalletStatus `json:"wallet,omitempty"`
Services common.AplicationServicesStatus `json:"services,omitempty"`
Wallet WalletStatus `json:"wallet,omitempty"`
}

func (status *Status) Clone() *Status {
return &Status{
Services: maps.Clone(status.Services),
Wallet: status.Wallet,
Services: common.AplicationServicesStatus{
Applications: maps.Clone(status.Services.Applications),
Timestamp: status.Services.Timestamp,
},
Wallet: status.Wallet,
}
}

Expand All @@ -35,7 +39,10 @@ func (statusUpdate *StatusUpdate) GetData() any {

func GetEmptyStatus() *Status {
return &Status{
Services: make(map[string]common.ApplicationServices),
Services: common.AplicationServicesStatus{
Applications: make(map[string]common.ApplicationServices),
Timestamp: time.Now().Unix(),
},
}
}

Expand All @@ -57,7 +64,8 @@ func SetupModule(ctx context.Context, configuration *configuration.TezpayModuleC
switch statusUpdate := statusUpdate.(type) {
case *common.ServicesStatusUpdate:
application := statusUpdate.Application
tezpayStatus.Services[application] = statusUpdate.Status
tezpayStatus.Services.Applications[application] = statusUpdate.Status
tezpayStatus.Services.Timestamp = time.Now().Unix()
case *WalletBalanceUpdate:
tezpayStatus.Wallet = statusUpdate.Status
}
Expand Down
5 changes: 4 additions & 1 deletion web/src/components/app/PayoutsCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
goto('/tezpay');
}
$: hasTezpayStatus = !!$services.applications?.tezpay?.['tezpay'];
$: isTezpayRunning = $services.applications?.tezpay?.['tezpay']?.status === 'running';
</script>

Expand All @@ -24,7 +25,9 @@
<div class="payouts-info">
<div class="row" />
<div class="property">Automatic Payouts:</div>
{#if isTezpayRunning}
{#if !hasTezpayStatus}
<div class="value automatic-payouts-status warn">UNKNOWN</div>
{:else if isTezpayRunning}
<div class="value automatic-payouts-status ok">ACTIVE</div>
{:else}
<div class="value automatic-payouts-status warn">INACTIVE</div>
Expand Down

0 comments on commit 7a8951c

Please sign in to comment.