mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-10-04 21:32:39 +08:00
workspace status update api
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/asaskevich/govalidator"
|
||||
"github.com/lib/pq"
|
||||
"github.com/onepanelio/core/pkg/util"
|
||||
"github.com/onepanelio/core/pkg/util/ptr"
|
||||
"google.golang.org/grpc/codes"
|
||||
@@ -103,13 +104,28 @@ func (c *Client) CreateWorkspace(namespace string, workspace *Workspace) (*Works
|
||||
}
|
||||
|
||||
func (c *Client) UpdateWorkspaceStatus(namespace, uid string, status *WorkspaceStatus) (err error) {
|
||||
fieldMap := sq.Eq{
|
||||
"phase": status.Phase,
|
||||
}
|
||||
|
||||
switch status.Phase {
|
||||
case WorkspaceStarted:
|
||||
fieldMap["paused_at"] = pq.NullTime{}
|
||||
fieldMap["started_at"] = time.Now().UTC()
|
||||
break
|
||||
case WorkspacePausing:
|
||||
fieldMap["started_at"] = pq.NullTime{}
|
||||
fieldMap["paused_at"] = time.Now().UTC()
|
||||
break
|
||||
case WorkspaceTerminating:
|
||||
fieldMap["started_at"] = pq.NullTime{}
|
||||
fieldMap["paused_at"] = pq.NullTime{}
|
||||
fieldMap["terminated_at"] = time.Now().UTC()
|
||||
break
|
||||
}
|
||||
|
||||
_, err = sb.Update("workspaces").
|
||||
SetMap(sq.Eq{
|
||||
"phase": status.Phase,
|
||||
"started_at": status.StartedAt,
|
||||
"paused_at": status.PausedAt,
|
||||
"terminated_at": status.TerminatedAt,
|
||||
}).
|
||||
SetMap(fieldMap).
|
||||
Where(sq.Eq{
|
||||
"namespace": namespace,
|
||||
"uid": uid,
|
||||
|
@@ -67,14 +67,8 @@ func (s *WorkspaceServer) UpdateWorkspaceStatus(ctx context.Context, req *api.Up
|
||||
return &empty.Empty{}, err
|
||||
}
|
||||
|
||||
started, _ := time.Parse(TimeLayout, req.Status.StartedAt)
|
||||
pausedAt, _ := time.Parse(TimeLayout, req.Status.PausedAt)
|
||||
terminatedAt, _ := time.Parse(TimeLayout, req.Status.TerminatingAt)
|
||||
status := &v1.WorkspaceStatus{
|
||||
Phase: v1.WorkspacePhase(req.Status.Phase),
|
||||
StartedAt: &started,
|
||||
PausedAt: &pausedAt,
|
||||
TerminatedAt: &terminatedAt,
|
||||
Phase: v1.WorkspacePhase(req.Status.Phase),
|
||||
}
|
||||
err = client.UpdateWorkspaceStatus(req.Namespace, req.Uid, status)
|
||||
|
||||
|
Reference in New Issue
Block a user