Skip to content

Commit

Permalink
✨ Move more things to Stages
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Jan 18, 2024
1 parent c2acef0 commit 8b82987
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 47 deletions.
6 changes: 1 addition & 5 deletions lib/class/task_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let running_task_menu,
*
* @author Jelle De Loecker <[email protected]>
* @since 1.3.17
* @version 1.3.17
* @version 1.4.0
*/
const Service = Function.inherits('Alchemy.Base', 'Alchemy.Task', function TaskService() {

Expand All @@ -33,10 +33,6 @@ const Service = Function.inherits('Alchemy.Base', 'Alchemy.Task', function TaskS
this.initSchedules();

singleton = this;

if (alchemy.settings.task.janeway_menu) {
this.createJanewayTaskMenu();
}
});

/**
Expand Down
26 changes: 4 additions & 22 deletions lib/core/alchemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,30 +412,10 @@ Alchemy.setMethod(function setMaxEventLoopLag(max_lag) {
*
* @author Jelle De Loecker <[email protected]>
* @since 1.3.17
* @version 1.3.17
* @version 1.4.0
*/
Alchemy.setMethod(function afterStart() {
this.startTaskService();
});

let task_service_has_started = false;

/**
* Start the task service
*
* @author Jelle De Loecker <[email protected]>
* @since 1.3.17
* @version 1.3.17
*/
Alchemy.setMethod(function startTaskService() {

if (task_service_has_started) {
return;
}

task_service_has_started = true;

this.task_service = new Classes.Alchemy.Task.TaskService();

});

/**
Expand Down Expand Up @@ -2366,6 +2346,8 @@ Alchemy.setMethod(function start(options, callback) {
STAGES.launch([
'load_app',
'datasource',
'tasks',
'settings',
'routes',
'server',
]);
Expand Down
14 changes: 0 additions & 14 deletions lib/stages/10-datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,4 @@ const connect = datasource.createStage('connect', () => {
});

return Function.parallel(tasks);
});

/**
* "datasource.connect.load_settings"
* Load any possible settings in the database
*
* @author Jelle De Loecker <[email protected]>
* @since 1.4.0
* @version 1.4.0
*
* @type {Alchemy.Stages.Stage}
*/
const load_settings = connect.createStage('load_settings', () => {
console.log('Should load settings..')
});
27 changes: 27 additions & 0 deletions lib/stages/15-tasks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* The "tasks" stage
*
* @author Jelle De Loecker <[email protected]>
* @since 1.4.0
* @version 1.4.0
*
* @type {Alchemy.Stages.Stage}
*/
const tasks = STAGES.createStage('tasks');

// Do not start any task stage before the datasources are connected
tasks.dependsOn('datasource.connect');

/**
* "tasks.start_service"
* Start the task service
*
* @author Jelle De Loecker <[email protected]>
* @since 1.4.0
* @version 1.4.0
*
* @type {Alchemy.Stages.Stage}
*/
const start_service = tasks.createStage('start_service', () => {
alchemy.task_service = new Classes.Alchemy.Task.TaskService();
});
54 changes: 54 additions & 0 deletions lib/stages/20-settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* The "settings" stage.
* The settings definitions should already be loaded.
* The hard-coded settings too.
* In this stage, we load the settings from the database.
*
* @author Jelle De Loecker <[email protected]>
* @since 1.4.0
* @version 1.4.0
*
* @type {Alchemy.Stages.Stage}
*/
const settings = STAGES.createStage('settings');

// Do not start this stage before the datasources are connected
settings.dependsOn('datasource.connect');

/**
* "settings.load"
* Load the settings from the database
*
* @author Jelle De Loecker <[email protected]>
* @since 1.4.0
* @version 1.4.0
*
* @type {Alchemy.Stages.Stage}
*/
const load = settings.createStage('load', async () => {

let records = await Model.get('AlchemySetting').find('all');

if (!records.length) {
return;
}

for (let record of records) {
await record.applySetting(false);
}
});


/**
* "datasource.connect.load_settings"
* Load any possible settings in the database
*
* @author Jelle De Loecker <[email protected]>
* @since 1.4.0
* @version 1.4.0
*
* @type {Alchemy.Stages.Stage}
*/
const perform_actions = settings.createStage('perform_actions', async () => {
await alchemy.system_settings.performAllActions();
});
File renamed without changes.
7 changes: 1 addition & 6 deletions lib/stages/30-server.js → lib/stages/90-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,7 @@ const start = server.createStage('start', () => {
alchemy.setSetting('network.socket', address);
log.info('HTTP server listening on socket file', address);

const set_socketfile_chmod = alchemy.getSetting('network.socketfile_chmod');

// Make readable by everyone
if (set_socketfile_chmod) {
libfs.chmodSync(address, set_socketfile_chmod);
}
alchemy.executeSetting('network.socketfile_chmod');
} else {
// Get the actual server port
alchemy.setSetting('network.port', address.port);
Expand Down

0 comments on commit 8b82987

Please sign in to comment.