mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
app is working again. new structure for blocks. new useWaveObjectValueWithSuspense hook
This commit is contained in:
@@ -4,49 +4,17 @@
|
||||
package blockservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/wavetermdev/thenextwave/pkg/blockcontroller"
|
||||
"github.com/wavetermdev/thenextwave/pkg/wstore"
|
||||
)
|
||||
|
||||
type BlockService struct{}
|
||||
|
||||
const DefaultTimeout = 2 * time.Second
|
||||
|
||||
func (bs *BlockService) CreateBlock(bdef *wstore.BlockDef, rtOpts *wstore.RuntimeOpts) (*wstore.Block, error) {
|
||||
ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancelFn()
|
||||
if bdef == nil {
|
||||
return nil, fmt.Errorf("block definition is nil")
|
||||
}
|
||||
if rtOpts == nil {
|
||||
return nil, fmt.Errorf("runtime options is nil")
|
||||
}
|
||||
blockData, err := blockcontroller.CreateBlock(ctx, bdef, rtOpts)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating block: %w", err)
|
||||
}
|
||||
return blockData, nil
|
||||
}
|
||||
|
||||
func (bs *BlockService) CloseBlock(blockId string) {
|
||||
blockcontroller.CloseBlock(blockId)
|
||||
}
|
||||
|
||||
func (bs *BlockService) GetBlockData(blockId string) (*wstore.Block, error) {
|
||||
ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancelFn()
|
||||
blockData, err := wstore.DBGet[*wstore.Block](ctx, blockId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting block data: %w", err)
|
||||
}
|
||||
return blockData, nil
|
||||
}
|
||||
|
||||
func (bs *BlockService) SendCommand(blockId string, cmdMap map[string]any) error {
|
||||
cmd, err := blockcontroller.ParseCmdMap(cmdMap)
|
||||
if err != nil {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/wavetermdev/thenextwave/pkg/blockcontroller"
|
||||
"github.com/wavetermdev/thenextwave/pkg/waveobj"
|
||||
"github.com/wavetermdev/thenextwave/pkg/wstore"
|
||||
)
|
||||
@@ -109,3 +110,25 @@ func (svc *ObjectService) SetActiveTab(uiContext wstore.UIContext, tabId string)
|
||||
}
|
||||
return updatesRtn(ctx, nil)
|
||||
}
|
||||
|
||||
func (svc *ObjectService) CreateBlock(uiContext wstore.UIContext, blockDef *wstore.BlockDef, rtOpts *wstore.RuntimeOpts) (any, error) {
|
||||
if uiContext.ActiveTabId == "" {
|
||||
return nil, fmt.Errorf("no active tab")
|
||||
}
|
||||
ctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout)
|
||||
defer cancelFn()
|
||||
ctx = wstore.ContextWithUpdates(ctx)
|
||||
blockData, err := wstore.CreateBlock(ctx, uiContext.ActiveTabId, blockDef, rtOpts)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating block: %w", err)
|
||||
}
|
||||
if blockData.Controller != "" {
|
||||
err = blockcontroller.StartBlockController(ctx, blockData.OID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error starting block controller: %w", err)
|
||||
}
|
||||
}
|
||||
rtn := make(map[string]any)
|
||||
rtn["blockid"] = blockData.OID
|
||||
return updatesRtn(ctx, rtn)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user