-
Notifications
You must be signed in to change notification settings - Fork 13
feat: force cleanup at boot with SYNC_FORCE_REMOVE=true
#956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
michael-0acf4
merged 7 commits into
main
from
met-799-clear-out-cached-typegraphs-on-boot
Jan 11, 2025
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
74fbd47
feat: force cleanup at boot with
michael-0acf4 0e3404b
fix: cleanup before history sync
michael-0acf4 a9d12b2
fix: address comment
michael-0acf4 72e1a5b
fix: published_test.ts
michael-0acf4 481e9b8
test: force remove on sync mode
michael-0acf4 8d2e2a4
Merge branch 'main' into met-799-clear-out-cached-typegraphs-on-boot
michael-0acf4 2aaefed
Merge branch 'main' into met-799-clear-out-cached-typegraphs-on-boot
Yohe-Am File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
export function hello({ name }: { name: string }) { | ||
return `Hello ${name}`; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
from typegraph import t, typegraph, Policy, Graph | ||
from typegraph.runtimes.deno import DenoRuntime | ||
|
||
|
||
@typegraph() | ||
def sync(g: Graph): | ||
deno = DenoRuntime() | ||
public = Policy.public() | ||
|
||
g.expose( | ||
hello=deno.import_( | ||
t.struct({"name": t.string()}), | ||
t.string(), | ||
name="hello", | ||
module="scripts/hello.ts", | ||
secrets=["ULTRA_SECRET"], | ||
).with_policy(public) | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
import { gql, Meta } from "test-utils/mod.ts"; | ||
import { connect } from "redis"; | ||
import { S3Client } from "aws-sdk/client-s3"; | ||
import { createBucket, listObjects, tryDeleteBucket } from "test-utils/s3.ts"; | ||
import { assertEquals } from "@std/assert"; | ||
import { clearSyncData, setupSync } from "test-utils/hooks.ts"; | ||
import { Typegate } from "@metatype/typegate/typegate/mod.ts"; | ||
import { | ||
defaultTypegateConfigBase, | ||
getTypegateConfig, | ||
SyncConfig, | ||
} from "@metatype/typegate/config.ts"; | ||
|
||
const redisKey = "typegraph"; | ||
const redisEventKey = "typegraph_event"; | ||
|
||
async function cleanUp(config: typeof syncConfig) { | ||
using redis = await connect(config.redis); | ||
await redis.del(redisKey); | ||
await redis.del(redisEventKey); | ||
|
||
const s3 = new S3Client(config.s3); | ||
await tryDeleteBucket(s3, config.s3Bucket); | ||
await createBucket(s3, config.s3Bucket); | ||
s3.destroy(); | ||
await redis.quit(); | ||
} | ||
|
||
const syncConfig = { | ||
redis: { | ||
hostname: "localhost", | ||
port: 6379, | ||
password: "password", | ||
db: 1, | ||
}, | ||
s3: { | ||
endpoint: "http://localhost:9000", | ||
region: "local", | ||
credentials: { | ||
accessKeyId: "minio", | ||
secretAccessKey: "password", | ||
}, | ||
forcePathStyle: true, | ||
}, | ||
s3Bucket: "metatype-deno-runtime-sync-test", | ||
}; | ||
|
||
async function spawnGate(syncConfig: SyncConfig) { | ||
const config = getTypegateConfig({ | ||
base: { | ||
...defaultTypegateConfigBase, | ||
}, | ||
}); | ||
|
||
return await Typegate.init({ | ||
...config, | ||
sync: syncConfig, | ||
}); | ||
} | ||
|
||
Meta.test( | ||
{ | ||
name: "Force cleanup at boot on sync mode", | ||
syncConfig, | ||
async setup() { | ||
await clearSyncData(syncConfig); | ||
await setupSync(syncConfig); | ||
}, | ||
async teardown() { | ||
await cleanUp(syncConfig); | ||
}, | ||
}, | ||
async (t) => { | ||
await t.should( | ||
"cleanup if forceRemove is true", | ||
async () => { | ||
const _engine = await t.engine("sync/sync.py", { | ||
secrets: { | ||
ULTRA_SECRET: | ||
"if_you_can_read_me_on_an_ERROR_there_is_a_bug", | ||
}, | ||
}); | ||
|
||
const s3 = new S3Client(syncConfig.s3); | ||
const initialObjects = await listObjects(s3, syncConfig.s3Bucket); | ||
assertEquals(initialObjects?.length, 3); | ||
|
||
const gateNoRemove = await spawnGate(syncConfig); | ||
const namesNoRemove = gateNoRemove.register.list().map(({ name }) => | ||
name | ||
); | ||
|
||
const gateAfterRemove = await spawnGate({ | ||
...syncConfig, | ||
forceRemove: true, | ||
}); | ||
const namesAfterRemove = gateAfterRemove.register.list().map(( | ||
{ name }, | ||
) => name); | ||
|
||
t.addCleanup(async () => { | ||
await gateNoRemove[Symbol.asyncDispose](); | ||
await gateAfterRemove[Symbol.asyncDispose](); | ||
}); | ||
|
||
assertEquals(namesNoRemove, ["sync"]); | ||
assertEquals(namesAfterRemove, []); // ! | ||
}, | ||
); | ||
}, | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.