Skip to content

Commit

Permalink
fix(schedule.mjs): bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
supersonictw committed Apr 7, 2024
1 parent b606fe9 commit e74c94d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const pluginPromises = [
// Define schedule tasks
const scheduleTasks = [{
name: "refresh",
config: {
options: {
time: "0 6 * * *",
},
}];
Expand Down
17 changes: 7 additions & 10 deletions src/init/schedule.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ import schedule from "node-schedule";
* @param {object[]} tasks the tasks to load
*/
export async function startScheduleTasks(tasks) {
for (const {name: methodName, config: methodConfig} of tasks) {
const createMethod = (name, options) => () => {
const methodDirectory = new URL("../tasks/", import.meta.url);
const methodFilename = new URL(`${methodName}.mjs`, methodDirectory);

const createMethod = (options) => () => {
import(methodFilename).then((f) => f.default(options));
};
for (const config of methodConfig) {
const method = createMethod(config);
schedule.scheduleJob(config.time, method);
}
const methodFilename = new URL(`${name}.mjs`, methodDirectory);
import(methodFilename).then((f) => f.default(options));
};
for (const {name, options} of tasks) {
const method = createMethod(name, options);
schedule.scheduleJob(options.time, method);
}
}

0 comments on commit e74c94d

Please sign in to comment.