-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add paused sandboxes to the list of running sandboxes #264
base: main
Are you sure you want to change the base?
Changes from 13 commits
3648bbd
0f32b7e
43ec9c0
351bad6
6c087c7
5576498
b9a9fd5
5c8a41e
fba4230
fcb5725
1444bab
44c6148
7b91e46
46d5cd6
17c4117
c08cd0f
c465572
f427051
399686d
fb571ce
94ca02c
e5d64b5
15f5570
f3fd4c9
2903259
82663a2
8cafa93
5545200
128ff4f
7349956
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,50 +24,60 @@ func (a *APIStore) GetSandboxesSandboxID(c *gin.Context, id string) { | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you change the event above? 🙏🏻 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not seeing the line you're talking about? |
||
sandboxId := strings.Split(id, "-")[0] | ||
|
||
// Try to get the running instance first | ||
info, err := a.orchestrator.GetInstance(ctx, sandboxId) | ||
if err != nil { | ||
c.JSON(http.StatusNotFound, fmt.Sprintf("instance \"%s\" doesn't exist or you don't have access to it", id)) | ||
if err == nil && *info.TeamID == team.ID { | ||
mishushakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Instance exists and belongs to the team - return running sandbox info | ||
mishushakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
build, err := a.db.Client.EnvBuild.Query().Where(envbuild.ID(*info.BuildID)).First(ctx) | ||
mishushakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
telemetry.ReportCriticalError(ctx, err) | ||
mishushakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
c.JSON(http.StatusInternalServerError, fmt.Sprintf("Error getting build for instance %s", id)) | ||
return | ||
} | ||
|
||
instance := api.RunningSandbox{ | ||
ClientID: info.Instance.ClientID, | ||
TemplateID: info.Instance.TemplateID, | ||
Alias: info.Instance.Alias, | ||
SandboxID: info.Instance.SandboxID, | ||
StartedAt: info.StartTime, | ||
CpuCount: int32(build.Vcpu), | ||
MemoryMB: int32(build.RAMMB), | ||
EndAt: info.EndTime, | ||
State: "running", | ||
mishushakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if info.Metadata != nil { | ||
meta := api.SandboxMetadata(info.Metadata) | ||
instance.Metadata = &meta | ||
} | ||
|
||
c.JSON(http.StatusOK, instance) | ||
return | ||
} | ||
|
||
if *info.TeamID != team.ID { | ||
c.JSON(http.StatusNotFound, fmt.Sprintf("instance \"%s\" doesn't exist or you don't have access to it", id)) | ||
return | ||
} | ||
|
||
a.posthog.IdentifyAnalyticsTeam(team.ID.String(), team.Name) | ||
properties := a.posthog.GetPackageToPosthogProperties(&c.Request.Header) | ||
a.posthog.CreateAnalyticsTeamEvent(team.ID.String(), "get running instance", properties) | ||
|
||
build, err := a.db.Client.EnvBuild.Query().Where(envbuild.ID(*info.BuildID)).First(ctx) | ||
// If instance not found or doesn't belong to team, try to get the latest snapshot | ||
snapshot, build, err := a.db.GetLastSnapshot(ctx, sandboxId, team.ID) | ||
if err != nil { | ||
telemetry.ReportCriticalError(ctx, err) | ||
c.JSON(http.StatusInternalServerError, fmt.Sprintf("Error getting build for instance %s", id)) | ||
|
||
fmt.Println(err) | ||
mishushakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
c.JSON(http.StatusNotFound, fmt.Sprintf("instance or snapshot \"%s\" doesn't exist or you don't have access to it", id)) | ||
return | ||
} | ||
|
||
memoryMB := int32(-1) | ||
cpuCount := int32(-1) | ||
|
||
if build != nil { | ||
memoryMB = int32(build.RAMMB) | ||
cpuCount = int32(build.Vcpu) | ||
} | ||
|
||
// optional | ||
mishushakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
instance := api.RunningSandbox{ | ||
ClientID: info.Instance.ClientID, | ||
TemplateID: info.Instance.TemplateID, | ||
Alias: info.Instance.Alias, | ||
SandboxID: info.Instance.SandboxID, | ||
StartedAt: info.StartTime, | ||
CpuCount: cpuCount, | ||
MemoryMB: memoryMB, | ||
EndAt: info.EndTime, | ||
ClientID: "00000000", | ||
mishushakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
TemplateID: snapshot.EnvID, | ||
SandboxID: snapshot.SandboxID, | ||
StartedAt: snapshot.SandboxStartedAt, | ||
CpuCount: int32(build.Vcpu), | ||
MemoryMB: int32(build.RAMMB), | ||
EndAt: snapshot.PausedAt, | ||
State: "paused", | ||
mishushakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if info.Metadata != nil { | ||
meta := api.SandboxMetadata(info.Metadata) | ||
if snapshot.Metadata != nil { | ||
meta := api.SandboxMetadata(snapshot.Metadata) | ||
instance.Metadata = &meta | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't used anywhere yet, right? Because it would be backward incompatible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What line are you mentioning? StartedAt is now nullable (but required) - it is used in the CLI and Dashboard