Fixed jobs and queries
This commit is contained in:
parent
643b4cdc20
commit
fae064a6db
4 changed files with 79 additions and 39 deletions
|
@ -2,7 +2,7 @@ import { useQuery } from '@tanstack/react-query'
|
|||
|
||||
const QUALITEER_URL = "https://qualiteer.elijahparker3.repl.co/api";
|
||||
|
||||
const useMock = true;
|
||||
const useMock = false;
|
||||
|
||||
const asMock = (data) => ({ data });
|
||||
|
||||
|
@ -21,5 +21,5 @@ export const usePipelineMappings = () => useMock ? asMock([
|
|||
export const useSilencedAlerts = () => useMock? asMock([]) : useQuery(['silenced'], fetchApi("/alerting/silenced")
|
||||
)
|
||||
|
||||
export const useCurrentlyFailing = () => useQuery(['failing'], useMock? asMock([]) : fetchApi("/results/failing")
|
||||
export const useCurrentlyFailing = () => useMock? asMock([]) : useQuery(['failing'], fetchApi("/results/failing")
|
||||
)
|
|
@ -15,6 +15,7 @@ const ACTIONS = {
|
|||
CREATE: "c",
|
||||
UPDATE: "u",
|
||||
DELETE: "d",
|
||||
PIPELINE: "p"
|
||||
};
|
||||
|
||||
const url = "https://qualiteer.elijahparker3.repl.co/";
|
||||
|
@ -34,7 +35,7 @@ pipelines: [{tracks:[
|
|||
|
||||
const reducer = (state, action) => {
|
||||
// Current Jobs
|
||||
const { jobs } = state;
|
||||
const { jobs, pipelines } = state;
|
||||
var jobIndex;
|
||||
// Actions
|
||||
switch (action.type) {
|
||||
|
@ -52,6 +53,8 @@ const reducer = (state, action) => {
|
|||
jobs.splice(jobIndex, 1);
|
||||
return { ...state, jobs };
|
||||
|
||||
case ACTIONS.PIPELINE:
|
||||
return {...state, pipelines};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -66,24 +69,7 @@ export const JobProvider = ({ children }) => {
|
|||
dispatch({ type: ACTIONS.CREATE, job: { ...job, log: [] } });
|
||||
const jobDelete = (jobId) => dispatch({ type: ACTIONS.DELETE, jobId });
|
||||
|
||||
function jobCancel(jobId){
|
||||
const job = state.jobs.find((j)=>j.jobId===jobId);
|
||||
if(job.initiator.sk)
|
||||
|
||||
job.initiator.sk.close();
|
||||
job.status = jobStatus.CANCELED;
|
||||
jobUpdate({ ...job }, jobId);
|
||||
|
||||
}
|
||||
|
||||
function jobDestroy(jobId){
|
||||
const job = state.jobs.find((j)=>j.jobId===jobId);
|
||||
if(job.initiator.sk && job.status !== jobStatus.OK && job.status !== jobStatus.ERROR && job.status !== jobStatus.CANCELED){
|
||||
job.initiator.sk.close();
|
||||
}
|
||||
|
||||
jobDelete(jobId);
|
||||
}
|
||||
const updatePipelines = (pipelines) => dispatch({type: ACTIONS.pipeline, pipelines});
|
||||
|
||||
function retryAll(failing) {
|
||||
// Query Full Locator
|
||||
|
@ -91,14 +77,76 @@ export const JobProvider = ({ children }) => {
|
|||
return jobFactory({ testNames: ["single"] });
|
||||
}
|
||||
|
||||
function pipelineComponentJob(jobPipeline, testName){
|
||||
const i = new Initiator(url);
|
||||
const jobId = `j${Date.now()}`;
|
||||
const job = {
|
||||
name: jobId,
|
||||
status: jobStatus.PENDING,
|
||||
jobId,
|
||||
isPipeline: true,
|
||||
builderCache: {},
|
||||
initiator: i,
|
||||
}
|
||||
const request = {
|
||||
testName,
|
||||
image: "node",
|
||||
type: "pipeline",
|
||||
name: jobId,
|
||||
pipelineTriggers: "secondary",
|
||||
};
|
||||
|
||||
jobCreate(job);
|
||||
const onLog = (d) => {
|
||||
const job = state.jobs.find((j) => j.jobId === jobId);
|
||||
job.log.push(d);
|
||||
job.status = jobStatus.ACTIVE;
|
||||
jobUpdate({ ...job }, jobId);
|
||||
};
|
||||
|
||||
const onClose = (c) => {
|
||||
const job = state.jobs.find((j) => j.jobId === jobId);
|
||||
job.exitcode = c;
|
||||
job.status = c === 0 ? jobStatus.OK : jobStatus.ERROR;
|
||||
jobUpdate({ ...job }, jobId);
|
||||
};
|
||||
const onPipelineTrigger = (trigger) => {
|
||||
console.log("Got trigger", trigger);
|
||||
}
|
||||
const started = i.newPipelineJob(request, onLog, onClose, onPipelineTrigger);
|
||||
started.then(() => jobUpdate({ status: jobStatus.ACTIVE }, jobId));
|
||||
|
||||
}
|
||||
|
||||
function pipelineFactory(builderCache) {
|
||||
console.log("Would create pipeline with cache");
|
||||
console.log(builderCache);
|
||||
return jobFactory({testNames: ["primary"]});
|
||||
return pipelineComponentJob(state.pipelines, builderCache.branches[0][0]);
|
||||
// return jobId;
|
||||
/*return jobFactory({testNames: ["primary"]});*/
|
||||
}
|
||||
|
||||
|
||||
function jobCancel(jobId){
|
||||
const job = state.jobs.find((j)=>j.jobId===jobId);
|
||||
|
||||
if(job.initiator.sk) job.initiator.sk.close();
|
||||
job.status = jobStatus.CANCELED;
|
||||
jobUpdate({ ...job }, jobId);
|
||||
|
||||
}
|
||||
|
||||
function jobDestroy(jobId){
|
||||
const job = state.jobs.find((j)=>j.jobId===jobId);
|
||||
|
||||
if(job.initiator.sk && job.status !== jobStatus.OK && job.status !== jobStatus.ERROR && job.status !== jobStatus.CANCELED){
|
||||
job.initiator.sk.close();
|
||||
}
|
||||
jobDelete(jobId);
|
||||
}
|
||||
|
||||
function jobFactory(builderCache) {
|
||||
if(builderCache.tracks) return pipelineFactory(builderCache);
|
||||
if(builderCache.tree) return pipelineFactory(builderCache);
|
||||
// Find test
|
||||
const i = new Initiator(url);
|
||||
const jobId = `j${Date.now()}`;
|
||||
|
@ -137,21 +185,9 @@ export const JobProvider = ({ children }) => {
|
|||
const started = i.newJob(request, onLog, onClose);
|
||||
started.then(() => jobUpdate({ status: jobStatus.ACTIVE }, jobId));
|
||||
|
||||
/*const job = {
|
||||
type: "compound",
|
||||
testName: "primary",
|
||||
pipelineTriggers: "secondary",
|
||||
name: "testing",
|
||||
image: "node",
|
||||
};*/
|
||||
return jobId;
|
||||
}
|
||||
|
||||
function retrySingle(test) {
|
||||
console.log("Would retry test", test);
|
||||
return jobFactory({ testNames: ["single"] });
|
||||
}
|
||||
|
||||
const context = {
|
||||
state,
|
||||
dispatch,
|
||||
|
@ -159,7 +195,6 @@ export const JobProvider = ({ children }) => {
|
|||
jobCreate,
|
||||
jobDelete,
|
||||
retryAll,
|
||||
retrySingle,
|
||||
jobFactory,
|
||||
jobCancel,
|
||||
jobDestroy
|
||||
|
|
|
@ -43,7 +43,7 @@ export default function Jobs() {
|
|||
): null}
|
||||
<JobBuilder />
|
||||
{location.hash === "" &&
|
||||
jobState.jobs.map((v, i) => (
|
||||
jobState.jobs.filter((j)=>!j.isPipeline).map((v, i) => (
|
||||
<a
|
||||
key={i}
|
||||
href={`/qualiteer/jobs#${v.name}`}
|
||||
|
|
|
@ -28,6 +28,11 @@ function PipelineSelector(props) {
|
|||
setCache({ primarySelectedMappings });
|
||||
};
|
||||
|
||||
const clickNext = () =>{
|
||||
if(!cache.primarySelectedMappings ) return console.log("No mapping selected")
|
||||
next()
|
||||
}
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<DialogContent>
|
||||
|
@ -59,7 +64,7 @@ function PipelineSelector(props) {
|
|||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button onClick={cancel}>Cancel</Button>
|
||||
<Button onClick={next} autoFocus>
|
||||
<Button onClick={clickNext} autoFocus>
|
||||
Next
|
||||
</Button>
|
||||
</DialogActions>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue