Skip to content

Commit b5413ea

Browse files
committed
make ephemeral accounts get an ephemeral project
1 parent 1750e91 commit b5413ea

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

src/packages/server/accounts/account-creation-actions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ export default async function accountCreationActions({
1616
account_id,
1717
tags,
1818
noFirstProject,
19+
ephemeral,
1920
}: {
2021
email_address?: string;
2122
account_id: string;
2223
tags?: string[];
2324
// if set, don't do any initial project actions (i.e., creating or starting projects)
2425
noFirstProject?: boolean;
26+
ephemeral?: number;
2527
}): Promise<void> {
2628
log.debug({ account_id, email_address, tags });
2729

@@ -56,7 +58,7 @@ export default async function accountCreationActions({
5658
const projects = await getProjects({ account_id, limit: 1 });
5759
if (projects.length == 0) {
5860
// you really have no projects at all.
59-
await firstProject({ account_id, tags });
61+
await firstProject({ account_id, tags, ephemeral });
6062
}
6163
} catch (err) {
6264
// non-fatal; they can make their own project

src/packages/server/accounts/create-account.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export default async function createAccount({
8181
account_id,
8282
tags,
8383
noFirstProject,
84+
ephemeral,
8485
});
8586
await creationActionsDone(account_id);
8687
} catch (error) {

src/packages/server/accounts/first-project.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ const log = getLogger("server:accounts:first-project");
2222
export default async function firstProject({
2323
account_id,
2424
tags,
25+
ephemeral,
2526
}: {
2627
account_id: string;
2728
tags?: string[];
29+
ephemeral?: number;
2830
}): Promise<string> {
2931
log.debug(account_id, tags);
3032
if (!isValidUUID(account_id)) {
@@ -33,6 +35,7 @@ export default async function firstProject({
3335
const project_id = await createProject({
3436
account_id,
3537
title: "My First Project",
38+
ephemeral,
3639
});
3740
log.debug("created new project", project_id);
3841
const project = getProject(project_id);
@@ -57,7 +60,7 @@ export default async function firstProject({
5760
account_id,
5861
project_id,
5962
language,
60-
welcome + jupyterExtra
63+
welcome + jupyterExtra,
6164
);
6265
}
6366
}
@@ -78,7 +81,7 @@ async function createJupyterNotebookIfAvailable(
7881
account_id: string,
7982
project_id: string,
8083
language: string,
81-
welcome: string
84+
welcome: string,
8285
): Promise<string> {
8386
// find the highest priority kernel with the given language
8487
let kernelspec: any = null;
@@ -129,7 +132,7 @@ async function createWelcome(
129132
account_id: string,
130133
project_id: string,
131134
ext: string,
132-
welcome: string
135+
welcome: string,
133136
): Promise<string> {
134137
const path = `welcome/welcome.${ext}`;
135138
const { torun } = TAGS_MAP[ext] ?? {};

src/packages/server/projects/create.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default async function createProject(opts: CreateProjectOptions) {
3434
public_path_id,
3535
noPool,
3636
start,
37+
ephemeral,
3738
} = opts;
3839
let license = opts.license;
3940
if (public_path_id) {
@@ -70,7 +71,7 @@ export default async function createProject(opts: CreateProjectOptions) {
7071

7172
project_id = v4();
7273
}
73-
74+
7475
const pool = getPool();
7576
const users =
7677
account_id == null ? null : { [account_id]: { group: "owner" } };
@@ -87,14 +88,15 @@ export default async function createProject(opts: CreateProjectOptions) {
8788
const envs = await getSoftwareEnvironments("server");
8889

8990
await pool.query(
90-
"INSERT INTO projects (project_id, title, description, users, site_license, compute_image, created, last_edited) VALUES($1, $2, $3, $4, $5, $6, NOW(), NOW())",
91+
"INSERT INTO projects (project_id, title, description, users, site_license, compute_image, created, last_edited, ephemeral) VALUES($1, $2, $3, $4, $5, $6, NOW(), NOW(), $7::BIGINT)",
9192
[
9293
project_id,
9394
title ?? "No Title",
9495
description ?? "",
9596
users != null ? JSON.stringify(users) : users,
9697
site_license != null ? JSON.stringify(site_license) : undefined,
9798
image ?? envs?.default ?? DEFAULT_COMPUTE_IMAGE,
99+
ephemeral ?? null,
98100
],
99101
);
100102

src/packages/util/db-schema/projects.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,8 @@ export interface CreateProjectOptions {
743743

744744
// admins can specify the project_id - nobody else can -- useful for debugging.
745745
project_id?: string;
746+
// if set, project should be treated as expiring after this many milliseconds since creation
747+
ephemeral?: number;
746748
}
747749

748750
interface BaseCopyOptions {

0 commit comments

Comments
 (0)