fix(striker-ui-api): correct update file location (pre an to per host)
This commit is contained in:
parent
76ab36e1f9
commit
f7350bef9f
@ -1,3 +1,4 @@
|
|||||||
|
import assert from 'assert';
|
||||||
import { RequestHandler } from 'express';
|
import { RequestHandler } from 'express';
|
||||||
|
|
||||||
import { anvilSyncShared, query, timestamp, write } from '../../accessModule';
|
import { anvilSyncShared, query, timestamp, write } from '../../accessModule';
|
||||||
@ -84,38 +85,26 @@ export const updateFile: RequestHandler = async (request, response) => {
|
|||||||
modified_date = '${timestamp()}'
|
modified_date = '${timestamp()}'
|
||||||
WHERE file_location_uuid = '${fileLocationUUID}';`;
|
WHERE file_location_uuid = '${fileLocationUUID}';`;
|
||||||
|
|
||||||
const targetHosts: [
|
// Each file location entry is for 1 host.
|
||||||
n1uuid: string,
|
const rows = await query<[[string]]>(
|
||||||
n2uuid: string,
|
`SELECT file_location_host_uuid
|
||||||
dr1uuid: null | string,
|
FROM file_locations
|
||||||
][] = await query(
|
WHERE file_location_uuid = '${fileLocationUUID}';`,
|
||||||
`SELECT
|
|
||||||
anv.anvil_node1_host_uuid,
|
|
||||||
anv.anvil_node2_host_uuid,
|
|
||||||
anv.anvil_dr1_host_uuid
|
|
||||||
FROM anvils AS anv
|
|
||||||
JOIN file_locations AS fil_loc
|
|
||||||
ON fil_loc.file_location_host_uuid IN (
|
|
||||||
anv.anvil_node1_host_uuid,
|
|
||||||
anv.anvil_node2_host_uuid,
|
|
||||||
anv.anvil_dr1_host_uuid
|
|
||||||
)
|
|
||||||
WHERE fil_loc.file_location_uuid = '${fileLocationUUID}';`,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
targetHosts.flat().forEach((hostUUID: null | string) => {
|
if (rows.length) {
|
||||||
if (hostUUID) {
|
const [[hostUuid]] = rows;
|
||||||
anvilSyncSharedFunctions.push(() =>
|
|
||||||
anvilSyncShared(
|
anvilSyncSharedFunctions.push(() =>
|
||||||
jobName,
|
anvilSyncShared(
|
||||||
`file_uuid=${fileUUID}`,
|
jobName,
|
||||||
jobTitle,
|
`file_uuid=${fileUUID}`,
|
||||||
jobDescription,
|
jobTitle,
|
||||||
{ jobHostUUID: hostUUID },
|
jobDescription,
|
||||||
),
|
{ jobHostUUID: hostUuid },
|
||||||
);
|
),
|
||||||
}
|
);
|
||||||
});
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -124,6 +113,8 @@ export const updateFile: RequestHandler = async (request, response) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
wcode = await write(sqlscript);
|
wcode = await write(sqlscript);
|
||||||
|
|
||||||
|
assert(wcode === 0, `Write exited with code ${wcode}`);
|
||||||
} catch (queryError) {
|
} catch (queryError) {
|
||||||
stderr(`Failed to execute query; CAUSE: ${queryError}`);
|
stderr(`Failed to execute query; CAUSE: ${queryError}`);
|
||||||
|
|
||||||
@ -134,5 +125,5 @@ export const updateFile: RequestHandler = async (request, response) => {
|
|||||||
stdoutVar(await fn(), `Anvil sync shared [${index}] output: `),
|
stdoutVar(await fn(), `Anvil sync shared [${index}] output: `),
|
||||||
);
|
);
|
||||||
|
|
||||||
response.status(200).send(wcode);
|
response.status(200).send();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user