Skip to content

Commit 1ea377e

Browse files
authored
Clean up successful and failed jobs (#343)
* clean up * annoying log nit * feedback
1 parent 9be5522 commit 1ea377e

File tree

7 files changed

+20
-3
lines changed

7 files changed

+20
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Fixed
1515
- Text highlighting clarity. [#342](https://github.com/sourcebot-dev/sourcebot/pull/342)
16+
- Clean up successful and failed jobs in Redis queues. [#343](https://github.com/sourcebot-dev/sourcebot/pull/343)
1617

1718
## [4.2.0] - 2025-06-09
1819

docs/docs/configuration/environment-variables.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ The following environment variables allow you to configure your Sourcebot deploy
2323
| `EMAIL_FROM_ADDRESS` | `-` | <p>The email address that transactional emails will be sent from. See [this doc](/docs/configuration/transactional-emails) for more info.</p> |
2424
| `REDIS_DATA_DIR` | `$DATA_CACHE_DIR/redis` | <p>The data directory for the default Redis instance.</p> |
2525
| `REDIS_URL` | `redis://localhost:6379` | <p>Connection string of your Redis instance. By default, a Redis database is automatically provisioned at startup within the container.</p> |
26+
| `REDIS_REMOVE_ON_COMPLETE` | `0` | <p>Controls how many completed jobs are allowed to remain in Redis queues</p> |
27+
| `REDIS_REMOVE_ON_FAIL` | `100` | <p>Controls how many failed jobs are allowed to remain in Redis queues</p> |
2628
| `SHARD_MAX_MATCH_COUNT` | `10000` | <p>The maximum shard count per query</p> |
2729
| `SMTP_CONNECTION_URL` | `-` | <p>The url to the SMTP service used for sending transactional emails. See [this doc](/docs/configuration/transactional-emails) for more info.</p> |
2830
| `SOURCEBOT_ENCRYPTION_KEY` | Automatically generated at startup if no value is provided. Generated using `openssl rand -base64 24` | <p>Used to encrypt connection secrets and generate API keys.</p> |

packages/backend/src/connectionManager.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ export class ConnectionManager implements IConnectionManager {
6464
connectionName: connection.name,
6565
orgId: connection.orgId,
6666
config: connectionConfig,
67+
}, {
68+
removeOnComplete: env.REDIS_REMOVE_ON_COMPLETE,
69+
removeOnFail: env.REDIS_REMOVE_ON_FAIL,
6770
});
6871
this.logger.info(`Added job to queue for connection ${connection.name} (id: ${connection.id})`);
6972
}).catch((err: unknown) => {

packages/backend/src/env.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export const env = createEnv({
3535
FALLBACK_GITEA_CLOUD_TOKEN: z.string().optional(),
3636

3737
REDIS_URL: z.string().url().default("redis://localhost:6379"),
38+
REDIS_REMOVE_ON_COMPLETE: numberSchema.default(0),
39+
REDIS_REMOVE_ON_FAIL: numberSchema.default(100),
3840

3941
NEXT_PUBLIC_SENTRY_BACKEND_DSN: z.string().optional(),
4042
NEXT_PUBLIC_SENTRY_ENVIRONMENT: z.string().optional(),

packages/backend/src/repoManager.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { existsSync, readdirSync, promises } from 'fs';
1010
import { indexGitRepository } from "./zoekt.js";
1111
import { PromClient } from './promClient.js';
1212
import * as Sentry from "@sentry/node";
13+
import { env } from './env.js';
1314

1415
interface IRepoManager {
1516
validateIndexedReposHaveShards: () => Promise<void>;
@@ -106,8 +107,10 @@ export class RepoManager implements IRepoManager {
106107
name: 'repoIndexJob',
107108
data: { repo },
108109
opts: {
109-
priority: priority
110-
}
110+
priority: priority,
111+
removeOnComplete: env.REDIS_REMOVE_ON_COMPLETE,
112+
removeOnFail: env.REDIS_REMOVE_ON_FAIL,
113+
},
111114
})));
112115

113116
// Increment pending jobs counter for each repo added
@@ -396,6 +399,10 @@ export class RepoManager implements IRepoManager {
396399
await this.gcQueue.addBulk(repos.map(repo => ({
397400
name: 'repoGarbageCollectionJob',
398401
data: { repo },
402+
opts: {
403+
removeOnComplete: env.REDIS_REMOVE_ON_COMPLETE,
404+
removeOnFail: env.REDIS_REMOVE_ON_FAIL,
405+
}
399406
})));
400407

401408
logger.info(`Added ${repos.length} jobs to gcQueue`);

packages/web/src/env.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ export const env = createEnv({
6767
STRIPE_WEBHOOK_SECRET: z.string().optional(),
6868
STRIPE_ENABLE_TEST_CLOCKS: booleanSchema.default('false'),
6969

70+
LOGTAIL_TOKEN: z.string().optional(),
71+
LOGTAIL_HOST: z.string().url().optional(),
72+
7073
// Misc
7174
CONFIG_MAX_REPOS_NO_TOKEN: numberSchema.default(Number.MAX_SAFE_INTEGER),
7275
NODE_ENV: z.enum(["development", "test", "production"]),

packages/web/src/features/entitlements/server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ export const getPlan = (): Plan => {
7979

8080
return licenseKey.seats === SOURCEBOT_UNLIMITED_SEATS ? "self-hosted:enterprise-unlimited" : "self-hosted:enterprise";
8181
} else {
82-
logger.info(`No valid license key found. Falling back to oss plan.`);
8382
return "oss";
8483
}
8584
}

0 commit comments

Comments
 (0)