| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 | 
							- import async from "async";
 
- import { isAdminRequired } from "./hooks";
 
- import moduleManager from "../../index";
 
- const UtilsModule = moduleManager.modules.utils;
 
- export default {
 
- 	getModules: isAdminRequired(function getModules(session, cb) {
 
- 		async.waterfall(
 
- 			[
 
- 				next => {
 
- 					next(null, UtilsModule.moduleManager.modules);
 
- 				},
 
- 				(modules, next) => {
 
- 					// this.log(modules, next);
 
- 					next(
 
- 						null,
 
- 						Object.keys(modules).map(moduleName => {
 
- 							const module = modules[moduleName];
 
- 							return {
 
- 								name: module.name,
 
- 								status: module.status,
 
- 								stage: module.stage,
 
- 								jobsInQueue: module.jobQueue.lengthQueue(),
 
- 								jobsInProgress: module.jobQueue.lengthRunning(),
 
- 								jobsPaused: module.jobQueue.lengthPaused(),
 
- 								concurrency: module.jobQueue.concurrency
 
- 							};
 
- 						})
 
- 					);
 
- 				}
 
- 			],
 
- 			async (err, modules) => {
 
- 				if (err && err !== true) {
 
- 					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
 
- 					this.log("ERROR", "GET_MODULES", `User ${session.userId} failed to get modules. '${err}'`);
 
- 					cb({ status: "error", message: err });
 
- 				} else {
 
- 					this.log("SUCCESS", "GET_MODULES", `User ${session.userId} has successfully got the modules info.`);
 
- 					cb({
 
- 						status: "success",
 
- 						message: "Successfully got modules.",
 
- 						data: { modules }
 
- 					});
 
- 				}
 
- 			}
 
- 		);
 
- 	}),
 
- 	getModule: isAdminRequired(function getModule(session, moduleName, cb) {
 
- 		async.waterfall(
 
- 			[
 
- 				next => {
 
- 					next(null, UtilsModule.moduleManager.modules[moduleName]);
 
- 				}
 
- 			],
 
- 			async (err, module) => {
 
- 				// this.log(module.runningJobs);
 
- 				if (err && err !== true) {
 
- 					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
 
- 					this.log("ERROR", "GET_MODULE", `User ${session.userId} failed to get module. '${err}'`);
 
- 					cb({ status: "error", message: err });
 
- 				} else {
 
- 					this.log("SUCCESS", "GET_MODULE", `User ${session.userId} has successfully got the module info.`);
 
- 					cb({
 
- 						status: "success",
 
- 						message: "Successfully got module info.",
 
- 						data: {
 
- 							// runningTasks: module.jobQueue.runningTasks,
 
- 							// pausedTasks: module.jobQueue.pausedTasks,
 
- 							// queuedTasks: module.jobQueue.queue,
 
- 							jobStatistics: module.jobStatistics
 
- 						}
 
- 					});
 
- 				}
 
- 			}
 
- 		);
 
- 	})
 
- };
 
 
  |