Skip to content

Commit

Permalink
set service to sleep mode (#4427)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianedwards authored Mar 21, 2024
1 parent bdc702d commit 9eef645
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 59 deletions.
26 changes: 13 additions & 13 deletions dashboard/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"@babel/preset-typescript": "^7.15.0",
"@ianvs/prettier-plugin-sort-imports": "^4.1.1",
"@pmmmwh/react-refresh-webpack-plugin": "^0.4.3",
"@porter-dev/api-contracts": "^0.2.118",
"@porter-dev/api-contracts": "^0.2.131",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
Expand Down
3 changes: 3 additions & 0 deletions dashboard/src/assets/moon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions dashboard/src/lib/porter-apps/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export const serviceValidator = z.object({
}),
smartOptimization: serviceBooleanValidator.optional(),
terminationGracePeriodSeconds: serviceNumberValidator.optional(),
sleep: serviceBooleanValidator.optional(),
config: z.discriminatedUnion("type", [
webConfigValidator,
workerConfigValidator,
Expand Down Expand Up @@ -148,6 +149,7 @@ export type SerializedService = {
gpuCoresNvidia: number;
};
terminationGracePeriodSeconds?: number;
sleep?: boolean;
config:
| {
type: "web";
Expand Down Expand Up @@ -314,6 +316,7 @@ export function serializeService(service: ClientService): SerializedService {
gpuCoresNvidia: service.gpu.gpuCoresNvidia.value,
},
terminationGracePeriodSeconds: service.terminationGracePeriodSeconds?.value,
sleep: service.sleep?.value,
config: match(service.config)
.with({ type: "web" }, (config) =>
Object.freeze({
Expand Down Expand Up @@ -386,6 +389,7 @@ export function deserializeService({
instances: ServiceField.number(service.instances, override?.instances),
port: ServiceField.number(service.port, override?.port),
cpuCores: ServiceField.number(service.cpuCores, override?.cpuCores),
sleep: ServiceField.boolean(service.sleep, override?.sleep),
gpu: {
enabled: ServiceField.boolean(
service.gpu?.enabled,
Expand Down Expand Up @@ -600,6 +604,7 @@ export function serviceProto(service: SerializedService): Service {
runOptional: service.run,
instancesOptional: service.instances,
type: serviceTypeEnumProto(config.type),
sleep: service.sleep,
config: {
value: {
...config,
Expand All @@ -616,6 +621,7 @@ export function serviceProto(service: SerializedService): Service {
runOptional: service.run,
instancesOptional: service.instances,
type: serviceTypeEnumProto(config.type),
sleep: service.sleep,
config: {
value: {
...config,
Expand Down Expand Up @@ -678,6 +684,7 @@ export function serializedServiceFromProto({
...service,
run: service.runOptional ?? service.run,
instances: service.instancesOptional ?? service.instances,
sleep: service.sleep,
config: {
type: "web" as const,
autoscaling: value.autoscaling ? value.autoscaling : undefined,
Expand All @@ -690,6 +697,7 @@ export function serializedServiceFromProto({
...service,
run: service.runOptional ?? service.run,
instances: service.instancesOptional ?? service.instances,
sleep: service.sleep,
config: {
type: "worker" as const,
autoscaling: value.autoscaling ? value.autoscaling : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {

import chip from "assets/computer-chip.svg";
import job from "assets/job.png";
import moon from "assets/moon.svg";
import web from "assets/web.png";
import worker from "assets/worker.png";

Expand Down Expand Up @@ -112,6 +113,15 @@ const ServiceContainer: React.FC<ServiceProps> = ({
</TagContainer>
</>
)}
{service.sleep?.value && (
<>
<Spacer inline x={1.5} />
<TagContainer disableAnimation>
<ChipIcon src={moon} alt="Moon" />
<TagText>Sleeping</TagText>
</TagContainer>
</>
)}
</ServiceTitle>

{service.canDelete && (
Expand Down Expand Up @@ -260,7 +270,9 @@ const reflectiveGleam = keyframes`
}
`;

const TagContainer = styled.div`
const TagContainer = styled.div<{
disableAnimation?: boolean;
}>`
box-sizing: border-box;
display: flex;
flex-direction: row;
Expand All @@ -277,7 +289,8 @@ const TagContainer = styled.div`
);
background-size: 200% 200%;
border-radius: 10px;
animation: ${reflectiveGleam} 4s infinite linear;
animation: ${reflectiveGleam} ${(props) =>
props.disableAnimation ? "" : "4s infinite"}
border: 1px solid rgba(255, 255, 255, 0.2);
`;

Expand Down
Loading

0 comments on commit 9eef645

Please sign in to comment.