feat: Ensure async workflow executions have access to shared container (#8157)
* feat: Ensure async workflow executions have access to shared container * fix: Register workflow worker on application start
This commit is contained in:
1 parent
1acfdc4ffe
commit
26d600b6db
15 files changed
+140
-38
No files matched your search
@@ -56,6 +56,8 @@ export async function initModules({
|
||||
injectedDependencies,
|
||||
})
|
||||
|
||||
await medusaApp.onApplicationStart()
|
||||
|
||||
async function shutdown() {
|
||||
if (shouldDestroyConnectionAutomatically) {
|
||||
await medusaApp.onApplicationPrepareShutdown()
|
||||
|
||||
@@ -145,6 +145,7 @@ export const ModulesDefinition: {
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
__passSharedContainer: true,
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
|
||||
@@ -139,6 +139,15 @@ export async function loadInternalModule(
|
||||
)
|
||||
}
|
||||
|
||||
if (resolution.definition.__passSharedContainer) {
|
||||
localContainer.register(
|
||||
"sharedContainer",
|
||||
asFunction(() => {
|
||||
return container
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
const loaders = moduleResources.loaders ?? loadedModule?.loaders ?? []
|
||||
const error = await runLoaders(loaders, {
|
||||
container,
|
||||
|
||||
@@ -233,6 +233,7 @@ export type MedusaAppOutput = {
|
||||
generateMigrations: GenerateMigrations
|
||||
onApplicationShutdown: () => Promise<void>
|
||||
onApplicationPrepareShutdown: () => Promise<void>
|
||||
onApplicationStart: () => Promise<void>
|
||||
sharedContainer?: MedusaContainer
|
||||
}
|
||||
|
||||
@@ -284,6 +285,10 @@ async function MedusaApp_({
|
||||
await promiseAll([MedusaModule.onApplicationPrepareShutdown()])
|
||||
}
|
||||
|
||||
const onApplicationStart = async () => {
|
||||
await MedusaModule.onApplicationStart()
|
||||
}
|
||||
|
||||
const modules: MedusaModuleConfig =
|
||||
modulesConfig ??
|
||||
(
|
||||
@@ -349,6 +354,7 @@ async function MedusaApp_({
|
||||
return {
|
||||
onApplicationShutdown,
|
||||
onApplicationPrepareShutdown,
|
||||
onApplicationStart,
|
||||
modules: allModules,
|
||||
link: undefined,
|
||||
query: async () => {
|
||||
@@ -536,6 +542,7 @@ async function MedusaApp_({
|
||||
return {
|
||||
onApplicationShutdown,
|
||||
onApplicationPrepareShutdown,
|
||||
onApplicationStart,
|
||||
modules: allModules,
|
||||
link: remoteLink,
|
||||
query,
|
||||
@@ -551,11 +558,7 @@ async function MedusaApp_({
|
||||
export async function MedusaApp(
|
||||
options: MedusaAppOptions = {}
|
||||
): Promise<MedusaAppOutput> {
|
||||
try {
|
||||
return await MedusaApp_(options)
|
||||
} finally {
|
||||
MedusaModule.onApplicationStart(options.onApplicationStartCb)
|
||||
}
|
||||
return await MedusaApp_(options)
|
||||
}
|
||||
|
||||
export async function MedusaAppMigrateUp(
|
||||
|
||||
@@ -87,6 +87,8 @@ export type ModuleDefinition = {
|
||||
isRequired?: boolean
|
||||
isQueryable?: boolean // If the module is queryable via Remote Joiner
|
||||
dependencies?: string[]
|
||||
/** @internal only used in exceptional cases - relying on the shared contrainer breaks encapsulation */
|
||||
__passSharedContainer?: boolean
|
||||
defaultModuleDeclaration:
|
||||
| InternalModuleDeclaration
|
||||
| ExternalModuleDeclaration
|
||||
|
||||
Reference in new issue
Block a user