Skip to content

Commit 8ad29c0

Browse files
authored
Merge pull request #266 from AthennaIO/develop
chore(ignite): dont refire ignite if running multiple apps
2 parents 1726b01 + 00fd4bd commit 8ad29c0

File tree

5 files changed

+48
-5
lines changed

5 files changed

+48
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@athenna/core",
3-
"version": "5.30.0",
3+
"version": "5.31.0",
44
"description": "One foundation for multiple applications.",
55
"license": "MIT",
66
"author": "João Lenon <lenon@athenna.io>",

src/ignite/Ignite.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { Repl as ReplApp } from '#src/applications/Repl'
3535
import { parse as semverParse, satisfies as semverSatisfies } from 'semver'
3636
import { Is, Path, File, Module, Options, Macroable } from '@athenna/common'
3737
import { NotSatisfiedNodeVersion } from '#src/exceptions/NotSatisfiedNodeVersion'
38+
import { debug } from '#src/debug/index'
3839

3940
export class Ignite extends Macroable {
4041
/**
@@ -57,6 +58,11 @@ export class Ignite extends Macroable {
5758
*/
5859
public options: IgniteOptions
5960

61+
/**
62+
* Holds if Ignite has already been fired.
63+
*/
64+
public hasFired: boolean = false
65+
6066
/**
6167
* Install source maps support if the --enable-source-maps
6268
* flag is not set.
@@ -167,7 +173,7 @@ export class Ignite extends Macroable {
167173
try {
168174
this.options.environments.push('http')
169175

170-
await this.fire()
176+
await this.fire(options?.forceIgniteFire)
171177

172178
return await Http.boot(options)
173179
} catch (err) {
@@ -182,7 +188,7 @@ export class Ignite extends Macroable {
182188
try {
183189
this.options.environments.push('cron')
184190

185-
await this.fire()
191+
await this.fire(options?.forceIgniteFire)
186192

187193
return await Cron.boot(options)
188194
} catch (err) {
@@ -197,7 +203,7 @@ export class Ignite extends Macroable {
197203
try {
198204
this.options.environments.push('worker')
199205

200-
await this.fire()
206+
await this.fire(options?.forceIgniteFire)
201207

202208
return await Worker.boot(options)
203209
} catch (err) {
@@ -209,7 +215,17 @@ export class Ignite extends Macroable {
209215
* Fire the application configuring the env variables file, configuration files
210216
* providers and preload files.
211217
*/
212-
public async fire() {
218+
public async fire(forceIgniteFire?: boolean) {
219+
if (this.hasFired && !forceIgniteFire) {
220+
debug(
221+
'application already fired. if you need to refire use forceIgniteFire option in your application bootstrap.'
222+
)
223+
224+
return
225+
}
226+
227+
this.hasFired = true
228+
213229
try {
214230
this.setEnvVariablesFile()
215231
await this.setConfigurationFiles()

src/types/CronOptions.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
*/
99

1010
export type CronOptions = {
11+
/**
12+
* Force ignite to fire. If running multiple applications, Athenna will
13+
* fire Ignite only on the first application bootstrap. Use this option
14+
* if you want to force the Ignite fire for a specific application.
15+
*
16+
* @default false
17+
*/
18+
forceIgniteFire: boolean
19+
1120
/**
1221
* The path to the cron routes.
1322
*

src/types/HttpOptions.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
*/
99

1010
export type HttpOptions = {
11+
/**
12+
* Force ignite to fire. If running multiple applications, Athenna will
13+
* fire Ignite only on the first application bootstrap. Use this option
14+
* if you want to force the Ignite fire for a specific application.
15+
*
16+
* @default false
17+
*/
18+
forceIgniteFire: boolean
19+
1120
/**
1221
* Only initialize the server without booting it. Useful when you want to
1322
* deploy your application in a serverless environment.

src/types/WorkerOptions.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
*/
99

1010
export type WorkerOptions = {
11+
/**
12+
* Force ignite to fire. If running multiple applications, Athenna will
13+
* fire Ignite only on the first application bootstrap. Use this option
14+
* if you want to force the Ignite fire for a specific application.
15+
*
16+
* @default false
17+
*/
18+
forceIgniteFire: boolean
19+
1120
/**
1221
* The path to the worker routes.
1322
*

0 commit comments

Comments
 (0)