fix #109: kill DO to avoid extra usage
parent
4bcf4173ea
commit
813ec1ab96
|
|
@ -94,6 +94,12 @@ export default {
|
||||||
locationHint: doLoc as DurableObjectLocationHint,
|
locationHint: doLoc as DurableObjectLocationHint,
|
||||||
})
|
})
|
||||||
resp = await doStub.getLocationAndStatus(monitor)
|
resp = await doStub.getLocationAndStatus(monitor)
|
||||||
|
try {
|
||||||
|
// Kill the DO instance after use, to avoid extra resource usage
|
||||||
|
await doStub.kill()
|
||||||
|
} catch (err) {
|
||||||
|
// An error here is expected, ignore it
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
resp = await (
|
resp = await (
|
||||||
await fetch(monitor.checkProxy, {
|
await fetch(monitor.checkProxy, {
|
||||||
|
|
@ -339,4 +345,12 @@ export class RemoteChecker extends DurableObject {
|
||||||
status: status,
|
status: status,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async kill() {
|
||||||
|
// Throwing an error in `blockConcurrencyWhile` will terminate the Durable Object instance
|
||||||
|
// https://developers.cloudflare.com/durable-objects/api/state/#blockconcurrencywhile
|
||||||
|
this.ctx.blockConcurrencyWhile(async () => {
|
||||||
|
throw 'killed'
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue