File tree Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change 7
7
* file that was distributed with this source code.
8
8
*/
9
9
10
+ import { stubsRoot } from '../stubs/main.js'
10
11
import type { CommandOptions } from '../types/ace.js'
11
12
import { args , BaseCommand , flags } from '../modules/ace/main.js'
12
13
@@ -97,6 +98,17 @@ export default class Configure extends BaseCommand {
97
98
} )
98
99
}
99
100
101
+ /**
102
+ * Configure health checks
103
+ */
104
+ async #configureHealthChecks( ) {
105
+ const codemods = await this . createCodemods ( )
106
+ await codemods . makeUsingStub ( stubsRoot , 'make/health/main.stub' , {
107
+ flags : this . parsed . flags ,
108
+ entity : this . app . generators . createEntity ( 'health' ) ,
109
+ } )
110
+ }
111
+
100
112
/**
101
113
* Creates codemods as per configure command options
102
114
*/
@@ -117,6 +129,9 @@ export default class Configure extends BaseCommand {
117
129
if ( this . name === 'edge' ) {
118
130
return this . #configureEdge( )
119
131
}
132
+ if ( this . name === 'health_checks' ) {
133
+ return this . #configureHealthChecks( )
134
+ }
120
135
121
136
const packageExports = await this . #getPackageSource( this . name )
122
137
if ( ! packageExports ) {
Original file line number Diff line number Diff line change
1
+ {{#var preloadFileName = string(entity.name).snakeCase().removeExtension().ext('.ts').toString()}}
2
+ {{{
3
+ exports({
4
+ to: app.startPath(entity.path, preloadFileName)
5
+ })
6
+ }}}
7
+ import {
8
+ HealthChecks,
9
+ DiskSpaceHealthCheck,
10
+ MemoryHeapHealthCheck,
11
+ } from '@adonisjs/core/health'
12
+
13
+ export const healthChecks = new HealthChecks().register([
14
+ new DiskSpaceHealthCheck(),
15
+ new MemoryHeapHealthCheck(),
16
+ ])
Original file line number Diff line number Diff line change @@ -411,3 +411,33 @@ test.group('Configure command | edge', (group) => {
411
411
)
412
412
} )
413
413
} )
414
+
415
+ test . group ( 'Configure command | health checks' , ( group ) => {
416
+ group . each . disableTimeout ( )
417
+
418
+ test ( 'create start/health file with some default checks' , async ( { assert, fs } ) => {
419
+ const ace = await new AceFactory ( ) . make ( fs . baseUrl )
420
+ await ace . app . init ( )
421
+ ace . ui . switchMode ( 'raw' )
422
+
423
+ await fs . createJson ( 'tsconfig.json' , { } )
424
+ await fs . create ( 'adonisrc.ts' , 'export default defineConfig({})' )
425
+
426
+ const command = await ace . create ( Configure , [ 'health_checks' ] )
427
+
428
+ await command . run ( )
429
+
430
+ assert . deepEqual ( command . ui . logger . getLogs ( ) , [
431
+ {
432
+ message : 'green(DONE:) create start/health.ts' ,
433
+ stream : 'stdout' ,
434
+ } ,
435
+ ] )
436
+
437
+ await assert . fileContains ( 'start/health.ts' , [
438
+ 'new DiskSpaceHealthCheck()' ,
439
+ 'new MemoryHeapHealthCheck()' ,
440
+ 'export const healthChecks = ' ,
441
+ ] )
442
+ } )
443
+ } )
You can’t perform that action at this time.
0 commit comments