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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user