@@ -26,7 +26,8 @@ import EventBusMixin from './EventBusMixin';
2626import WorkPanelMixin from ' ./WorkPanelMixin' ;
2727import SyncButton from ' ./SyncButton.vue' ;
2828import Utils from ' ../utils.js' ;
29- import { AbortController , Job } from ' @openeo/js-client' ;
29+ import { Job } from ' @openeo/js-client' ;
30+ import { cancellableRequest , showCancellableRequestError , CancellableRequestError } from ' ./cancellableRequest' ;
3031
3132const WorkPanelMixinInstance = WorkPanelMixin (' jobs' , ' batch job' , ' batch jobs' );
3233
@@ -39,8 +40,7 @@ export default {
3940 data () {
4041 return {
4142 watchers: {},
42- jobUpdater: null ,
43- runId: 0
43+ jobUpdater: null
4444 };
4545 },
4646 mounted () {
@@ -145,48 +145,20 @@ export default {
145145 await this .queueJob (job);
146146 },
147147 async executeProcess () {
148- let abortController = new AbortController ();
149- let snotifyConfig = {
150- timeout: 0 ,
151- type: ' async' ,
152- buttons: [{
153- text: ' Cancel' ,
154- action : toast => {
155- abortController .abort ();
156- this .$snotify .remove (toast .id , true );
157- }
158- }]
148+ const callback = async (abortController ) => {
149+ const result = await this .connection .computeResult (this .process , null , null , abortController);
150+ this .broadcast (' viewSyncResult' , result);
159151 };
160- let toast;
161152 try {
162- this .runId ++ ;
163- let message = " A process is currently executed synchronously..." ;
164- let title = ` Run #${ this .runId } ` ;
165- let endlessPromise = () => new Promise (() => {}); // Pass a promise to snotify that never resolves as we manually close the toast
166- toast = this .$snotify .async (message, title, endlessPromise, snotifyConfig);
167- let result = await this .connection .computeResult (this .process , null , null , abortController);
168- this .broadcast (' viewSyncResult' , result);
169- } catch (error) {
170- if (axios .isCancel (error)) {
171- // Do nothing, we expected the cancellation
172- }
173- else if (typeof error .message === ' string' && Utils .isObject (error .response ) && [400 ,500 ].includes (error .response .status )) {
174- this .broadcast (' viewLogs' , [{
175- id: error .id ,
176- code: error .code ,
177- level: ' error' ,
178- message: error .message ,
179- links: error .links || []
180- }]);
181- Utils .error (this , " Synchronous processing failed. Please see the logs for details." , " Processing Error" );
153+ await cancellableRequest (this , callback, ' Run' );
154+ } catch (error) {
155+ if (error instanceof CancellableRequestError) {
156+ showCancellableRequestError (this , error);
182157 }
183158 else {
184- Utils .exception (this , error, " Server Error" );
185- }
186- } finally {
187- if (toast) {
188- this .$snotify .remove (toast .id , true );
159+ Utils .exception (this , error);
189160 }
161+
190162 }
191163 },
192164 jobCreated (job ) {
0 commit comments