fix(striker-ui-api): simplify insert or update job

main
Tsu-ba-me 2 years ago
parent 5d81d4934d
commit d6e32c6c89
  1. 12
      striker-ui-api/src/lib/accessModule.ts
  2. 6
      striker-ui-api/src/lib/request_handlers/command/initializeStriker.ts
  3. 4
      striker-ui-api/src/lib/request_handlers/server/createServer.ts
  4. 6
      striker-ui-api/src/lib/request_handlers/server/getServerDetail.ts
  5. 5
      striker-ui-api/src/types/ExecModuleSubroutineFunction.d.ts

@ -46,11 +46,7 @@ const execModuleSubroutine = (
spawnSyncOptions,
subModuleName,
subParams,
}: {
spawnSyncOptions?: SpawnSyncOptions;
subModuleName?: string;
subParams?: Record<string, unknown>;
} = {},
}: ExecModuleSubroutineOptions = {},
) => {
const args = ['--sub', subName];
@ -78,6 +74,9 @@ const execModuleSubroutine = (
};
};
const dbInsertOrUpdateJob = (options?: ExecModuleSubroutineOptions) =>
execModuleSubroutine('insert_or_update_jobs', options).stdout;
const dbJobAnvilSyncShared = (
jobName: string,
jobData: string,
@ -110,7 +109,7 @@ const dbJobAnvilSyncShared = (
subParams.job_host_uuid = jobHostUUID;
}
return execModuleSubroutine('insert_or_update_jobs', { subParams }).stdout;
return dbInsertOrUpdateJob({ subParams });
};
const dbQuery = (query: string, options?: SpawnSyncOptions) => {
@ -146,6 +145,7 @@ const getLocalHostUUID = () =>
}).stdout;
export {
dbInsertOrUpdateJob as job,
dbJobAnvilSyncShared,
dbQuery,
dbSubRefreshTimestamp,

@ -9,7 +9,7 @@ import {
} from '../../consts/REG_EXP_PATTERNS';
import SERVER_PATHS from '../../consts/SERVER_PATHS';
import { sub } from '../../accessModule';
import { job } from '../../accessModule';
const fvar = (configStepCount: number, fieldName: string) =>
['form', `config_step${configStepCount}`, fieldName, 'value'].join('::');
@ -115,7 +115,7 @@ export const initializeStriker: RequestHandler<
}
try {
sub('insert_or_update_jobs', {
job({
subParams: {
file: __filename,
line: 0,
@ -155,7 +155,7 @@ ${buildNetworkLinks(2, networkShortName, interfaces)}`;
job_description: 'job_0071',
job_progress: 0,
},
}).stdout;
});
} catch (subError) {
console.log(`Failed to queue striker initialization; CAUSE: ${subError}`);

@ -5,7 +5,7 @@ import { OS_LIST_MAP } from '../../consts/OS_LIST';
import { REP_INTEGER, REP_UUID } from '../../consts/REG_EXP_PATTERNS';
import SERVER_PATHS from '../../consts/SERVER_PATHS';
import { dbQuery, sub } from '../../accessModule';
import { dbQuery, job } from '../../accessModule';
export const createServer: RequestHandler = ({ body }, response) => {
console.log('Creating server.');
@ -136,7 +136,7 @@ driver_iso=${dataDriverISO}`;
console.log(`provisionServerJobHostUUID: [${provisionServerJobHostUUID}]`);
sub('insert_or_update_jobs', {
job({
subParams: {
file: __filename,
line: 0,

@ -6,7 +6,7 @@ import path from 'path';
import { REP_UUID } from '../../consts/REG_EXP_PATTERNS';
import SERVER_PATHS from '../../consts/SERVER_PATHS';
import { dbQuery, getLocalHostUUID, sub } from '../../accessModule';
import { dbQuery, getLocalHostUUID, job } from '../../accessModule';
import { sanitizeQS } from '../../sanitizeQS';
import { mkfifo, rm } from '../../shell';
@ -127,7 +127,7 @@ export const getServerDetail: RequestHandler = (request, response) => {
}
try {
sub('insert_or_update_jobs', {
job({
subParams: {
file: __filename,
line: 0,
@ -143,7 +143,7 @@ out-file-id=${epoch}`,
job_progress: 0,
job_host_uuid: serverHostUUID,
},
}).stdout;
});
} catch (subError) {
console.log(
`Failed to queue fetch server screenshot job; CAUSE: ${subError}`,

@ -0,0 +1,5 @@
type ExecModuleSubroutineOptions = {
spawnSyncOptions?: import('child_process').SpawnSyncOptions;
subModuleName?: string;
subParams?: Record<string, unknown>;
};
Loading…
Cancel
Save