@@ -8,13 +8,10 @@ Convert LaTeX file to PDF using latexmk.
8
8
*/
9
9
10
10
import { exec } from "@cocalc/frontend/frame-editors/generic/client" ;
11
- import { TIMEOUT_CALLING_PROJECT } from "@cocalc/util/consts/project" ;
12
11
import type { ExecOutput } from "@cocalc/util/db-schema/projects" ;
13
12
import { change_filename_extension , path_split } from "@cocalc/util/misc" ;
14
13
import { ExecuteCodeOutputAsync } from "@cocalc/util/types/execute-code" ;
15
- import { TIMEOUT_LATEX_JOB_S } from "./constants" ;
16
- import { BuildLog } from "./types" ;
17
- import { gatherJobInfo , pdf_path } from "./util" ;
14
+ import { pdf_path , runJob } from "./util" ;
18
15
19
16
export async function latexmk (
20
17
project_id : string ,
@@ -38,59 +35,17 @@ export async function latexmk(
38
35
status ( [ command ] . concat ( args ) . join ( " " ) ) ;
39
36
}
40
37
41
- const job_info = await exec ( {
42
- bash : true , // we use ulimit so that the timeout on the backend is *enforced* via ulimit!!
43
- timeout : TIMEOUT_LATEX_JOB_S ,
38
+ // Step 1: Wait for the launched job to finish
39
+ const output = await runJob ( {
40
+ project_id ,
44
41
command,
45
42
args,
46
- project_id,
47
- path : head ,
48
- err_on_exit : false ,
43
+ rundir : head ,
49
44
aggregate : time ,
50
- async_call : true ,
45
+ set_job_info ,
51
46
} ) ;
52
47
53
- // Step 1: Wait for the launched job to finish
54
- let output : BuildLog ;
55
- if ( job_info . type !== "async" ) {
56
- output = job_info ;
57
- } else {
58
- set_job_info ( job_info ) ;
59
- gatherJobInfo ( project_id , job_info , set_job_info ) ;
60
-
61
- if ( typeof job_info . pid !== "number" ) {
62
- throw new Error ( "Unable to spawn LaTeX compile job." ) ;
63
- }
64
-
65
- while ( true ) {
66
- try {
67
- output = await exec ( {
68
- project_id,
69
- async_get : job_info . job_id ,
70
- async_await : true ,
71
- async_stats : true ,
72
- } ) ;
73
- // console.log("LaTeX/latexmk: got output=", output);
74
- if ( output . type !== "async" ) {
75
- throw new Error ( "not an async job" ) ;
76
- }
77
- set_job_info ( output ) ;
78
- break ;
79
- } catch ( err ) {
80
- // console.log("latexmk/while err=", err);
81
- if ( err === TIMEOUT_CALLING_PROJECT ) {
82
- // this will be fine, hopefully. We continue trying to get a reply
83
- await new Promise ( ( done ) => setTimeout ( done , 100 ) ) ;
84
- } else {
85
- throw new Error (
86
- "Unable to complete compilation. Check the project and try again..." ,
87
- ) ;
88
- }
89
- }
90
- }
91
- }
92
-
93
- // Step 2: do a copy operation
48
+ // Step 2: do a copy operation, if we run this in an output_directory (somewhere in /tmp)
94
49
if ( output_directory != null ) {
95
50
// We use cp instead of `ln -sf` so the file persists after project restart.
96
51
// Using a symlink would be faster and more efficient *while editing*,
0 commit comments