fix repo rm issue, 502 page, condition on test clock

This commit is contained in:
msukkari 2025-02-27 13:11:26 -08:00
parent cfff416e18
commit d0b75ce57d
3 changed files with 150 additions and 22 deletions

View file

@ -6,7 +6,7 @@ import { GithubConnectionConfig, GitlabConnectionConfig, GiteaConnectionConfig }
import { AppContext, Settings, RepoMetadata } from "./types.js";
import { getRepoPath, getTokenFromConfig, measure, getShardPrefix } from "./utils.js";
import { cloneRepository, fetchRepository } from "./git.js";
import { existsSync, rmSync, readdirSync, rm } from 'fs';
import { existsSync, readdirSync, promises } from 'fs';
import { indexGitRepository } from "./zoekt.js";
import os from 'os';
import { PromClient } from './promClient.js';
@ -189,16 +189,12 @@ export class RepoManager implements IRepoManager {
const repoPath = getRepoPath(repo, this.ctx);
const metadata = repo.metadata as RepoMetadata;
// If the repo was already in the indexing state, this job was likely killed and picked up again. As a result,
// to ensure the repo state is valid, we delete the repo if it exists so we get a fresh clone
if (repoAlreadyInIndexingState && existsSync(repoPath)) {
this.logger.info(`Deleting repo directory ${repoPath} during sync because it was already in the indexing state`);
await rm(repoPath, { recursive: true, force: true }, (err) => {
if (err) {
this.logger.error(`Failed to delete repo directory ${repoPath}: ${err}`);
throw err;
}
});
await promises.rm(repoPath, { recursive: true, force: true });
}
if (existsSync(repoPath)) {
@ -431,12 +427,7 @@ export class RepoManager implements IRepoManager {
const repoPath = getRepoPath(repo, this.ctx);
if (existsSync(repoPath)) {
this.logger.info(`Deleting repo directory ${repoPath}`);
await rm(repoPath, { recursive: true, force: true }, (err) => {
if (err) {
this.logger.error(`Failed to delete repo directory ${repoPath}: ${err}`);
throw err;
}
});
await promises.rm(repoPath, { recursive: true, force: true });
}
// delete shards
@ -445,12 +436,7 @@ export class RepoManager implements IRepoManager {
for (const file of files) {
const filePath = `${this.ctx.indexPath}/${file}`;
this.logger.info(`Deleting shard file ${filePath}`);
await rm(filePath, { force: true }, (err) => {
if (err) {
this.logger.error(`Failed to delete shard file ${filePath}: ${err}`);
throw err;
}
});
await promises.rm(filePath, { force: true });
}
}

View file

@ -0,0 +1,142 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sourcebot - Server Down</title>
<style>
:root {
--background: #0d1117;
--text: #ffffff;
--accent: #851EE7;
--secondary-bg: #161b22;
--border: #30363d;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
background-color: var(--background);
color: var(--text);
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
min-height: 100vh;
}
main {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 40px 20px;
text-align: center;
}
.server-down-container {
max-width: 600px;
background-color: var(--secondary-bg);
border-radius: 8px;
padding: 32px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
border: 1px solid var(--border);
}
.logo {
font-size: 64px;
font-weight: bold;
margin-bottom: 32px;
}
.logo-source {
color: var(--text);
}
.logo-bot {
color: var(--accent);
}
.dot {
color: var(--accent);
}
h1 {
font-size: 2.5rem;
margin-bottom: 16px;
}
.highlight {
color: var(--accent);
}
p {
font-size: 1.1rem;
line-height: 1.6;
margin-bottom: 24px;
opacity: 0.9;
}
.status-code {
font-family: monospace;
background-color: rgba(255, 255, 255, 0.1);
padding: 4px 8px;
border-radius: 4px;
font-weight: bold;
}
.retry-btn {
background-color: var(--accent);
color: white;
border: none;
padding: 12px 24px;
border-radius: 6px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: background-color 0.2s;
margin-top: 24px;
}
.retry-btn:hover {
background-color: #8a4dff;
}
footer {
padding: 16px;
text-align: center;
border-top: 1px solid var(--border);
font-size: 0.9rem;
opacity: 0.7;
margin-top: auto;
}
footer a {
color: var(--text);
margin: 0 12px;
text-decoration: none;
}
footer a:hover {
text-decoration: underline;
color: var(--accent);
}
</style>
</head>
<body>
<main>
<div class="server-down-container">
<div class="logo">
<span class="logo-source">Source</span><span class="logo-bot">bot</span><span class="dot">.</span>
</div>
<p>Our servers are currently down. We're working to get everything back online as quickly as possible, please try again later.</p>
</div>
</main>
<footer>
<a href="https://sourcebot.dev">About</a>
<a href="mailto:team@sourcebot.dev">Contact Us</a>
</footer>
</body>
</html>

View file

@ -822,9 +822,9 @@ export const createOnboardingSubscription = async (domain: string) =>
const stripe = getStripe();
// @nocheckin
const test_clock = await stripe.testHelpers.testClocks.create({
const test_clock = AUTH_URL !== "https://app.sourcebot.dev" ? await stripe.testHelpers.testClocks.create({
frozen_time: Math.floor(Date.now() / 1000)
});
}) : null;
// Use the existing customer if it exists, otherwise create a new one.
const customerId = await (async () => {
@ -835,7 +835,7 @@ export const createOnboardingSubscription = async (domain: string) =>
const customer = await stripe.customers.create({
name: org.name,
email: user.email ?? undefined,
test_clock: test_clock.id,
test_clock: test_clock?.id,
description: `Created by ${user.email} on ${domain} (id: ${org.id})`,
});