Skip to content

Commit

Permalink
feat: add rm-cache flag and bump to 81 (#653)
Browse files Browse the repository at this point in the history
* feat: add --rm-cache functionality

* feat: add cache removal check
  • Loading branch information
hussedev authored Sep 2, 2024
1 parent 448fc01 commit 64f2d08
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kill_timeout = '5s'
PASSPORT_SCORER_ID=335

[processes]
indexer = 'npm start -- --indexer --http'
indexer = 'npm start -- --indexer --http --rm-cache'
web = 'npm start -- --http --http-wait-for-sync=false'

[[mounts]]
Expand Down
9 changes: 8 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type CoingeckoSupportedChainId =
| 42220
| 1088;

const CHAIN_DATA_VERSION = "79";
const CHAIN_DATA_VERSION = "81";

export type Token = {
code: string;
Expand Down Expand Up @@ -1834,6 +1834,7 @@ export type Config = {
deploymentEnvironment: "local" | "development" | "staging" | "production";
enableResourceMonitor: boolean;
dropDb: boolean;
removeCache: boolean;
estimatesLinearQfWorkerPoolSize: number | null;
};

Expand Down Expand Up @@ -1900,6 +1901,9 @@ export function getConfig(): Config {
"drop-db": {
type: "boolean",
},
"rm-cache": {
type: "boolean",
},
"log-level": {
type: "string",
},
Expand Down Expand Up @@ -1986,6 +1990,8 @@ export function getConfig(): Config {

const dropDb = z.boolean().default(false).parse(args["drop-db"]);

const removeCache = z.boolean().default(false).parse(args["rm-cache"]);

const parseBoolean = z
.boolean()
.or(z.enum(["true", "false"]).transform((value) => value === "true"));
Expand Down Expand Up @@ -2031,6 +2037,7 @@ export function getConfig(): Config {
databaseUrl,
readOnlyDatabaseUrl,
dropDb,
removeCache,
dataVersion,
databaseSchemaName,
httpServerWaitForSync,
Expand Down
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ async function main(): Promise<void> {
});

if (config.cacheDir) {
if (config.removeCache) {
await fs.rm(config.cacheDir, { recursive: true });
try {
await fs.access(config.cacheDir);
baseLogger.error("Cache folder is not removed");
} catch (err) {
baseLogger.info("Cache folder is removed");
}
}
await fs.mkdir(config.cacheDir, { recursive: true });
}

Expand Down

0 comments on commit 64f2d08

Please sign in to comment.