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 QUALITEER_URL = "https://qualiteer.elijahparker3.repl.co/api";
|
||||||
|
|
||||||
const useMock = true;
|
const useMock = false;
|
||||||
|
|
||||||
const asMock = (data) => ({ data });
|
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 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",
|
CREATE: "c",
|
||||||
UPDATE: "u",
|
UPDATE: "u",
|
||||||
DELETE: "d",
|
DELETE: "d",
|
||||||
|
PIPELINE: "p"
|
||||||
};
|
};
|
||||||
|
|
||||||
const url = "https://qualiteer.elijahparker3.repl.co/";
|
const url = "https://qualiteer.elijahparker3.repl.co/";
|
||||||
|
@ -34,7 +35,7 @@ pipelines: [{tracks:[
|
||||||
|
|
||||||
const reducer = (state, action) => {
|
const reducer = (state, action) => {
|
||||||
// Current Jobs
|
// Current Jobs
|
||||||
const { jobs } = state;
|
const { jobs, pipelines } = state;
|
||||||
var jobIndex;
|
var jobIndex;
|
||||||
// Actions
|
// Actions
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
@ -52,6 +53,8 @@ const reducer = (state, action) => {
|
||||||
jobs.splice(jobIndex, 1);
|
jobs.splice(jobIndex, 1);
|
||||||
return { ...state, jobs };
|
return { ...state, jobs };
|
||||||
|
|
||||||
|
case ACTIONS.PIPELINE:
|
||||||
|
return {...state, pipelines};
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
@ -66,24 +69,7 @@ export const JobProvider = ({ children }) => {
|
||||||
dispatch({ type: ACTIONS.CREATE, job: { ...job, log: [] } });
|
dispatch({ type: ACTIONS.CREATE, job: { ...job, log: [] } });
|
||||||
const jobDelete = (jobId) => dispatch({ type: ACTIONS.DELETE, jobId });
|
const jobDelete = (jobId) => dispatch({ type: ACTIONS.DELETE, jobId });
|
||||||
|
|
||||||
function jobCancel(jobId){
|
const updatePipelines = (pipelines) => dispatch({type: ACTIONS.pipeline, pipelines});
|
||||||
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 retryAll(failing) {
|
function retryAll(failing) {
|
||||||
// Query Full Locator
|
// Query Full Locator
|
||||||
|
@ -91,14 +77,76 @@ export const JobProvider = ({ children }) => {
|
||||||
return jobFactory({ testNames: ["single"] });
|
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) {
|
function pipelineFactory(builderCache) {
|
||||||
console.log("Would create pipeline with cache");
|
console.log("Would create pipeline with cache");
|
||||||
console.log(builderCache);
|
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) {
|
function jobFactory(builderCache) {
|
||||||
if(builderCache.tracks) return pipelineFactory(builderCache);
|
if(builderCache.tree) return pipelineFactory(builderCache);
|
||||||
// Find test
|
// Find test
|
||||||
const i = new Initiator(url);
|
const i = new Initiator(url);
|
||||||
const jobId = `j${Date.now()}`;
|
const jobId = `j${Date.now()}`;
|
||||||
|
@ -136,22 +184,10 @@ export const JobProvider = ({ children }) => {
|
||||||
|
|
||||||
const started = i.newJob(request, onLog, onClose);
|
const started = i.newJob(request, onLog, onClose);
|
||||||
started.then(() => jobUpdate({ status: jobStatus.ACTIVE }, jobId));
|
started.then(() => jobUpdate({ status: jobStatus.ACTIVE }, jobId));
|
||||||
|
|
||||||
/*const job = {
|
|
||||||
type: "compound",
|
|
||||||
testName: "primary",
|
|
||||||
pipelineTriggers: "secondary",
|
|
||||||
name: "testing",
|
|
||||||
image: "node",
|
|
||||||
};*/
|
|
||||||
return jobId;
|
return jobId;
|
||||||
}
|
}
|
||||||
|
|
||||||
function retrySingle(test) {
|
|
||||||
console.log("Would retry test", test);
|
|
||||||
return jobFactory({ testNames: ["single"] });
|
|
||||||
}
|
|
||||||
|
|
||||||
const context = {
|
const context = {
|
||||||
state,
|
state,
|
||||||
dispatch,
|
dispatch,
|
||||||
|
@ -159,7 +195,6 @@ export const JobProvider = ({ children }) => {
|
||||||
jobCreate,
|
jobCreate,
|
||||||
jobDelete,
|
jobDelete,
|
||||||
retryAll,
|
retryAll,
|
||||||
retrySingle,
|
|
||||||
jobFactory,
|
jobFactory,
|
||||||
jobCancel,
|
jobCancel,
|
||||||
jobDestroy
|
jobDestroy
|
||||||
|
|
|
@ -43,7 +43,7 @@ export default function Jobs() {
|
||||||
): null}
|
): null}
|
||||||
<JobBuilder />
|
<JobBuilder />
|
||||||
{location.hash === "" &&
|
{location.hash === "" &&
|
||||||
jobState.jobs.map((v, i) => (
|
jobState.jobs.filter((j)=>!j.isPipeline).map((v, i) => (
|
||||||
<a
|
<a
|
||||||
key={i}
|
key={i}
|
||||||
href={`/qualiteer/jobs#${v.name}`}
|
href={`/qualiteer/jobs#${v.name}`}
|
||||||
|
|
|
@ -28,6 +28,11 @@ function PipelineSelector(props) {
|
||||||
setCache({ primarySelectedMappings });
|
setCache({ primarySelectedMappings });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const clickNext = () =>{
|
||||||
|
if(!cache.primarySelectedMappings ) return console.log("No mapping selected")
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
|
@ -59,7 +64,7 @@ function PipelineSelector(props) {
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button onClick={cancel}>Cancel</Button>
|
<Button onClick={cancel}>Cancel</Button>
|
||||||
<Button onClick={next} autoFocus>
|
<Button onClick={clickNext} autoFocus>
|
||||||
Next
|
Next
|
||||||
</Button>
|
</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue