Files
wehub-resource-sync bf9395e022
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / results (push) Has been cancelled
CI / deadcode (push) Has been cancelled
CI / e2e-live (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:22:54 +08:00

58 lines
1.4 KiB
Go

// Copyright (c) 2026 Lark Technologies Pte. Ltd.
// SPDX-License-Identifier: MIT
// Package busctl is the wire-level control client for the event bus daemon.
package busctl
import (
"bufio"
"bytes"
"fmt"
"time"
"github.com/larksuite/cli/internal/event/protocol"
"github.com/larksuite/cli/internal/event/transport"
)
const readTimeout = 5 * time.Second // matches protocol.WriteTimeout
func QueryStatus(tr transport.IPC, appID string) (*protocol.StatusResponse, error) {
conn, err := tr.Dial(tr.Address(appID))
if err != nil {
return nil, err
}
defer conn.Close()
if err := protocol.EncodeWithDeadline(conn, protocol.NewStatusQuery(), protocol.WriteTimeout); err != nil {
return nil, err
}
if err := conn.SetReadDeadline(time.Now().Add(readTimeout)); err != nil {
return nil, err
}
line, err := protocol.ReadFrame(bufio.NewReader(conn))
if err != nil {
return nil, err
}
msg, err := protocol.Decode(bytes.TrimRight(line, "\n"))
if err != nil {
return nil, err
}
resp, ok := msg.(*protocol.StatusResponse)
if !ok {
return nil, fmt.Errorf("unexpected response type from bus: %T", msg)
}
return resp, nil
}
// SendShutdown sends a Shutdown command; caller polls Dial to confirm exit.
func SendShutdown(tr transport.IPC, appID string) error {
conn, err := tr.Dial(tr.Address(appID))
if err != nil {
return err
}
defer conn.Close()
return protocol.EncodeWithDeadline(conn, protocol.NewShutdown(), protocol.WriteTimeout)
}