fix(medusa): Load subscribers and scheduled jobs in worker mode (#7769)
This commit is contained in:
@@ -15,6 +15,7 @@ import apiLoader from "./api"
|
|||||||
import loadConfig from "./config"
|
import loadConfig from "./config"
|
||||||
import expressLoader from "./express"
|
import expressLoader from "./express"
|
||||||
import featureFlagsLoader from "./feature-flags"
|
import featureFlagsLoader from "./feature-flags"
|
||||||
|
import { registerJobs } from "./helpers/register-jobs"
|
||||||
import { registerWorkflows } from "./helpers/register-workflows"
|
import { registerWorkflows } from "./helpers/register-workflows"
|
||||||
import { getResolvedPlugins } from "./helpers/resolve-plugins"
|
import { getResolvedPlugins } from "./helpers/resolve-plugins"
|
||||||
import { resolvePluginsLinks } from "./helpers/resolve-plugins-links"
|
import { resolvePluginsLinks } from "./helpers/resolve-plugins-links"
|
||||||
@@ -22,7 +23,6 @@ import { SubscriberLoader } from "./helpers/subscribers"
|
|||||||
import Logger from "./logger"
|
import Logger from "./logger"
|
||||||
import loadMedusaApp from "./medusa-app"
|
import loadMedusaApp from "./medusa-app"
|
||||||
import registerPgConnection from "./pg-connection"
|
import registerPgConnection from "./pg-connection"
|
||||||
import { registerJobs } from "./helpers/register-jobs"
|
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
directory: string
|
directory: string
|
||||||
@@ -33,6 +33,13 @@ const isWorkerMode = (configModule) => {
|
|||||||
return configModule.projectConfig.workerMode === "worker"
|
return configModule.projectConfig.workerMode === "worker"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const shouldLoadBackgroundProcessors = (configModule) => {
|
||||||
|
return (
|
||||||
|
configModule.projectConfig.workerMode === "worker" ||
|
||||||
|
configModule.projectConfig.workerMode === "shared"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
async function subscribersLoader(
|
async function subscribersLoader(
|
||||||
plugins: PluginDetails[],
|
plugins: PluginDetails[],
|
||||||
container: MedusaContainer
|
container: MedusaContainer
|
||||||
@@ -76,6 +83,11 @@ async function loadEntrypoints(
|
|||||||
ContainerRegistrationKeys.CONFIG_MODULE
|
ContainerRegistrationKeys.CONFIG_MODULE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (shouldLoadBackgroundProcessors(configModule)) {
|
||||||
|
await subscribersLoader(plugins, container)
|
||||||
|
await jobsLoader(plugins)
|
||||||
|
}
|
||||||
|
|
||||||
if (isWorkerMode(configModule)) {
|
if (isWorkerMode(configModule)) {
|
||||||
return async () => {}
|
return async () => {}
|
||||||
}
|
}
|
||||||
@@ -97,8 +109,6 @@ async function loadEntrypoints(
|
|||||||
})
|
})
|
||||||
|
|
||||||
await adminLoader({ app: expressApp, configModule, rootDirectory })
|
await adminLoader({ app: expressApp, configModule, rootDirectory })
|
||||||
await subscribersLoader(plugins, container)
|
|
||||||
await jobsLoader(plugins)
|
|
||||||
await apiLoader({
|
await apiLoader({
|
||||||
container,
|
container,
|
||||||
plugins,
|
plugins,
|
||||||
|
|||||||
Reference in New Issue
Block a user