Skip to content

Commit 24c469d

Browse files
authored
chore(): Run some commands in server mode only (medusajs#14202)
* chore(): Run some commands in server mode only * Create orange-timers-lay.md * chore(): Run some commands in server mode only * chore(): Run some commands in server mode only * chore(): Run some commands in server mode only
1 parent 008f5bb commit 24c469d

File tree

7 files changed

+20
-15
lines changed

7 files changed

+20
-15
lines changed

.changeset/orange-timers-lay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@medusajs/medusa": patch
3+
---
4+
5+
chore(): Run some commands in server mode only

packages/medusa/src/commands/db/migrate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ const main = async function ({
128128
executeSafeLinks,
129129
concurrency,
130130
}) {
131+
process.env.MEDUSA_WORKER_MODE = "server"
131132
const container = await initializeContainer(directory)
132133
const logger = container.resolve(ContainerRegistrationKeys.LOGGER)
133134

packages/medusa/src/commands/db/rollback.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { ensureDbExists } from "../utils"
1313
const TERMINAL_SIZE = process.stdout.columns
1414

1515
const main = async function ({ directory, modules }) {
16+
process.env.MEDUSA_WORKER_MODE = "server"
17+
1618
const container = await initializeContainer(directory)
1719
const logger = container.resolve(ContainerRegistrationKeys.LOGGER)
1820

packages/medusa/src/commands/db/run-scripts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ const main = async function ({
122122
directory: string
123123
container?: MedusaContainer
124124
}) {
125+
process.env.MEDUSA_WORKER_MODE = "server"
125126
const container = await initializeContainer(directory)
126127
const logger = container.resolve(ContainerRegistrationKeys.LOGGER)
127128

packages/medusa/src/commands/exec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ type Options = {
1515
}
1616

1717
export default async function exec({ file, args }: Options) {
18+
process.env.MEDUSA_WORKER_MODE = "server"
19+
1820
const container = await initializeContainer(process.cwd(), {
1921
skipDbConnection: true,
2022
})
@@ -41,8 +43,6 @@ export default async function exec({ file, args }: Options) {
4143
throw new Error(`File doesn't default export a function to execute.`)
4244
}
4345

44-
process.env.MEDUSA_WORKER_MODE = "server"
45-
4646
const { container } = await loaders({
4747
directory,
4848
expressApp: app,

packages/medusa/src/commands/user.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ export default async function ({
1414
track("CLI_USER", { with_id: !!id })
1515
const app = express()
1616
try {
17-
/**
18-
* Enabling worker mode to prevent discovering/loading
19-
* of API routes from the starter kit
20-
*/
21-
process.env.MEDUSA_WORKER_MODE = "worker"
17+
process.env.MEDUSA_WORKER_MODE = "server"
2218

2319
const { container } = await loaders({
2420
directory,

packages/medusa/src/loaders/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,6 @@ async function loadEntrypoints(
9191
ContainerRegistrationKeys.CONFIG_MODULE
9292
)
9393

94-
// Subscribers should be loaded no matter the worker mode, simply they will never handle anything
95-
// since worker/shared instances only will have a running worker to process events.
96-
await subscribersLoader(plugins, container)
97-
98-
if (shouldLoadBackgroundProcessors(configModule)) {
99-
await jobsLoader(plugins, container)
100-
}
101-
10294
if (isWorkerMode(configModule)) {
10395
return async () => {}
10496
}
@@ -202,6 +194,14 @@ export default async ({
202194
const workflowLoader = new WorkflowLoader(workflowsSourcePaths, container)
203195
await workflowLoader.load()
204196

197+
// Subscribers should be loaded no matter the worker mode, simply they will never handle anything
198+
// since worker/shared instances only will have a running worker to process events.
199+
await subscribersLoader(plugins, container)
200+
201+
if (shouldLoadBackgroundProcessors(configModule)) {
202+
await jobsLoader(plugins, container)
203+
}
204+
205205
const entrypointsShutdown = skipLoadingEntryPoints
206206
? () => {}
207207
: await loadEntrypoints(plugins, container, expressApp, rootDirectory)

0 commit comments

Comments
 (0)