Skip to content

Commit fcb8cd8

Browse files
feature: job status displayed
1 parent e24f46a commit fcb8cd8

File tree

7 files changed

+148
-56
lines changed

7 files changed

+148
-56
lines changed

bin/init-data/stemmarest/init_test_data.sh

+7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ else
5757
echo Created tradition $BESOIN_ID
5858
fi
5959

60+
echo; echo Adding stemweb_jobid 1 to Notre besoin
61+
$CURL --request PUT --header 'Content-Type: application/json' --data '{"stemweb_jobid":1}' $STEMMAREST_ENDPOINT/tradition/$BESOIN_ID
62+
6063
echo ...and its stemma
6164
$CURL --request POST --header 'Content-Type: application/json' --data @data/besoin_stemma.json $STEMMAREST_ENDPOINT/tradition/$BESOIN_ID/stemma
6265
if [ $? -ne 0 ]; then
@@ -80,6 +83,8 @@ if [ -z $FLOR_ID ]; then
8083
else
8184
echo Created tradition $FLOR_ID
8285
fi
86+
echo; echo Adding stemweb_jobid 2 to Florilegium
87+
$CURL --request PUT --header 'Content-Type: application/json' --data '{"stemweb_jobid":2}' $STEMMAREST_ENDPOINT/tradition/$FLOR_ID
8388
echo Uploading three sections
8489
for e in w x y; do
8590
$CURL --request POST --form name="section '$e'" --form file=@data/florilegium_${e}.csv --form filetype=csv $STEMMAREST_ENDPOINT/tradition/$FLOR_ID/section > /tmp/stemmarest.response
@@ -149,6 +154,8 @@ if [ -z $ASNIP_ID ]; then
149154
else
150155
echo Created tradition $ASNIP_ID
151156
fi
157+
echo; echo Adding stemweb_jobid 3 to Arabic test snippet
158+
$CURL --request PUT --header 'Content-Type: application/json' --data '{"stemweb_jobid":3}' $STEMMAREST_ENDPOINT/tradition/$ASNIP_ID
152159
# No stemma
153160

154161
echo; echo Creating admin-owned tradition

frontend/www/src/js/modules/common/components/icons.js

+34
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,40 @@ const svg_slide_indicator_active = `<svg
3030
<circle cx="12" cy="12" r="10"></circle>
3131
</svg>`;
3232

33+
const job_running_indicator = `<svg
34+
style="vertical-align: baseline;"
35+
class="indicator-svg"
36+
data-active="true"
37+
xmlns="http://www.w3.org/2000/svg"
38+
width="15"
39+
height="12"
40+
viewBox="0 -2 24 24"
41+
fill="#aae18b"
42+
stroke="currentColor"
43+
stroke-width="1"
44+
stroke-linecap="round"
45+
stroke-linejoin="round"
46+
>
47+
<circle cx="12" cy="12" r="10"></circle>
48+
</svg>`;
49+
50+
const job_error_indicator = `<svg
51+
style="vertical-align: baseline;"
52+
class="indicator-svg"
53+
data-active="true"
54+
xmlns="http://www.w3.org/2000/svg"
55+
width="15"
56+
height="12"
57+
viewBox="0 -2 24 24"
58+
fill="#dc3545"
59+
stroke="currentColor"
60+
stroke-width="1"
61+
stroke-linecap="round"
62+
stroke-linejoin="round"
63+
>
64+
<circle cx="12" cy="12" r="10"></circle>
65+
</svg>`;
66+
3367
const google_icon = `
3468
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><g id="feGoogle0" fill="none" fill-rule="evenodd" stroke="none" stroke-width="1"><g id="feGoogle1" fill="currentColor" fill-rule="nonzero"><path id="feGoogle2" d="M11.99 13.9v-3.72h9.36c.14.63.25 1.22.25 2.05c0 5.71-3.83 9.77-9.6 9.77c-5.52 0-10-4.48-10-10S6.48 2 12 2c2.7 0 4.96.99 6.69 2.61l-2.84 2.76c-.72-.68-1.98-1.48-3.85-1.48c-3.31 0-6.01 2.75-6.01 6.12s2.7 6.12 6.01 6.12c3.83 0 5.24-2.65 5.5-4.22h-5.51v-.01Z"/></g></g></svg>
3569
`;

frontend/www/src/js/modules/common/service/stemwebService.js

+9-31
Original file line numberDiff line numberDiff line change
@@ -142,44 +142,22 @@ class StemwebService extends BaseService {
142142
});
143143
}
144144

145-
/**
146-
* Lists the results of all jobs that have been run on the server by this
147-
* user.
148-
*
149-
* @returns {Promise<BaseResponse<RunJobResult[]>>}
150-
*/
151-
listRunResults() {
152-
return this.fetch(`/result`).then((response) => {
153-
if (response.success) {
154-
/** @type {{ results: RunJobResult[] }} } */
155-
const data = response.data;
156-
return data.results;
157-
}
158-
159-
// in case of failure, just return the response with the error
160-
return response;
161-
});
162-
}
163-
164145
/**
165146
* Gets the result of a job identified by the supplied `jobid` that has been
166147
* run on the server by this user.
167148
*
168149
* This can be used to periodically poll the server for the result of a job.
169150
*
170151
* @param jobid {string} The job ID of the job to fetch the result for.
171-
* @returns {Promise<BaseResponse<RunJobResult | null>>}
152+
* @returns {Promise<BaseResponse>>}
172153
*/
173-
getRunResult(jobid) {
174-
return this.fetch(`/result`, undefined, { jobid }).then((response) => {
175-
if (response.success) {
176-
/** @type {{ results: RunJobResult[] }} } */
177-
const data = response.data;
178-
return data.results.length > 0 ? data.results[0] : null;
179-
}
180-
181-
// in case of failure, just return the response with the error
182-
return response;
183-
});
154+
getRunResult( job_id ) {
155+
if( job_id ) {
156+
return this.fetch( `/algorithms/jobstatus/${job_id}` ).then((response) => {
157+
return response;
158+
});
159+
} else {
160+
return Promise.resolve( { success: true, message:'OK', data: { jobid: job_id, result: "No job id given.", status: undefined } } );
161+
}
184162
}
185163
}

frontend/www/src/js/modules/dashboard/tradition/editProperties.js

-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ class EditProperties extends HTMLElement {
113113
static #handleUpdateTraditionMetadataResponse(resp) {
114114
if (resp.success) {
115115
StemmawebAlert.show('Metadata properties updated.', 'success');
116-
// @todo: Should the next line be wrapped in a try..catch?
117116
TRADITION_STORE.updateTradition(resp.data);
118117
return Promise.resolve({
119118
success: true,

frontend/www/src/js/modules/dashboard/tradition/stemwebFrontend.js

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ class StemwebFrontend {
189189
handleRunAlgorithmResponse( resp ) {
190190
if (resp.success) {
191191
StemmawebAlert.show('Job added.', 'success');
192+
console.log( 'handleRunAlgorithmResponse =>', resp.data );
192193
// // @todo: Should the next line be wrapped in a try..catch?
193194
// TRADITION_STORE.updateTradition(resp.data);
194195
return Promise.resolve({

frontend/www/src/js/modules/dashboard/tradition/stemwebJobStatus.js

+95-23
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,105 @@
11

22
class StemwebJobStatus extends HTMLElement {
3+
34
constructor() {
45
super();
5-
}
6-
6+
// Whenever a new tradition / related stemma is selected, update the table
7+
STEMMA_STORE.subscribe(({ parentTradition, selectedStemma }) => {
8+
this.renderJobStatus( parentTradition.stemweb_jobid );
9+
});
10+
}
11+
712
connectedCallback() {
8-
this.render();
13+
// this.render();
14+
}
15+
16+
renderJobStatus( job_id ) {
17+
stemwebService.getRunResult( job_id )
18+
.then( this.handleJobStatusResponse )
19+
.then( (resp_data) => { this.render( resp_data ) } );
20+
}
21+
22+
handleJobStatusResponse( resp ) {
23+
if ( resp.success ) {
24+
return new Promise( ( resolve, reject ) => {
25+
resolve( resp.data );
26+
});
27+
} else {
28+
StemmawebAlert.show(`Error: ${resp.message}`, 'danger');
29+
return new Promise( ( resolve, reject ) => {
30+
resolve( undefined );
31+
});
32+
}
33+
}
34+
35+
36+
37+
statusTexts = {
38+
0: `Done`,
39+
1: `${job_running_indicator} Running`
40+
}
41+
42+
mapStatus( status ) {
43+
return this.statusTexts[ status ] || `${job_error_indicator} Error`
44+
}
45+
46+
jobStatusLabels = {
47+
job_id: 'Job',
48+
status: 'Status',
49+
result: 'Result'
50+
};
51+
52+
metadataFromJobStatus( resp_data ) {
53+
const labels = this.jobStatusLabels;
54+
return [
55+
{
56+
label: labels.job_id,
57+
value: resp_data.jobid
58+
},
59+
{
60+
label: labels.status,
61+
value: this.mapStatus( resp_data.status )
62+
},
63+
{ label: labels.result,
64+
value: resp_data.result
65+
}
66+
]
67+
}
68+
69+
70+
renderJobStatusItem(item) {
71+
return `
72+
<tr>
73+
<td class="tradition-property-label-cell">${item.label}</td>
74+
<td class="tradition-property-value-cell">${item.value}</td>
75+
</tr>
76+
`;
977
}
1078

11-
render() {
12-
const jobStatus = 'Hello World!'
13-
this.innerHTML = `
14-
<div class="position-sticky pt-3">
15-
<h6
16-
class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted"
17-
>
18-
<span>Job status</span>
19-
<!--maybe-goes-here-a-button/-->
20-
</h6>
21-
<div class="table-responsive px-3 py-3">
22-
<table class="table table-striped table-sm">
23-
<tbody id="job_status">
24-
${jobStatus}
25-
</tbody>
26-
</table>
27-
</div>
28-
29-
</div>
30-
`;
79+
render( resp_data ) {
80+
if ( resp_data.jobid ) {
81+
const statusItems = this.metadataFromJobStatus( resp_data );
82+
this.innerHTML = `
83+
<div class="position-sticky pt-3">
84+
<h6
85+
class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted"
86+
>
87+
<span>Job status</span>
88+
<!--maybe-goes-here-a-button/-->
89+
</h6>
90+
<div class="table-responsive px-3 py-3">
91+
<table class="table table-striped table-sm">
92+
<tbody id="job_status">
93+
${statusItems.map( this.renderJobStatusItem).join('\n') }
94+
</tbody>
95+
</table>
96+
</div>
97+
98+
</div>
99+
`;
100+
} else {
101+
this.innerHTML= '';
102+
}
31103
}
32104
}
33105

stemweb_mock/app.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from flask import Flask, request
2+
import time
23

34
app = Flask(__name__)
45

@@ -151,7 +152,7 @@ def run_job(algo):
151152

152153

153154
# Allow query of a job ID.
154-
@app.get('/algorithms/jobstatus/<jobid>')
155+
@app.get('/algorithms/jobstatus/<jobid>/')
155156
def query_job(jobid):
156157
if jobid == '1':
157158
return {"jobid":1,"status":0,"result":{

0 commit comments

Comments
 (0)