Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dtu-enote-getpdf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
enote
dtu-enote-getpdf
Commits
d55b9a97
Commit
d55b9a97
authored
7 years ago
by
Iain Bryson
Browse files
Options
Downloads
Patches
Plain Diff
Add route to cancel job.
Add common function to purge old jobs.
parent
159bc7c2
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
getpdf-server/src/agenda.js
+32
-1
32 additions, 1 deletion
getpdf-server/src/agenda.js
getpdf-server/src/api/getpdf.js
+16
-39
16 additions, 39 deletions
getpdf-server/src/api/getpdf.js
with
48 additions
and
40 deletions
getpdf-server/src/agenda.js
+
32
−
1
View file @
d55b9a97
...
...
@@ -8,6 +8,7 @@ import {ObjectId} from "mongojs";
import
initializeDb
from
'
./db
'
;
import
BuildPDFJob
from
'
./jobs/build_pdf_job
'
;
import
ZipJob
from
'
./jobs/zip_job
'
;
import
async
from
"
async
"
;
const
vol_root
=
process
.
env
.
DTU_ENOTE_VOL
||
"
/data
"
;
const
config_root
=
path
.
join
(
vol_root
,
"
config
"
);
...
...
@@ -42,7 +43,7 @@ initializeDb((dbs) => {
const
buildPDFJob
=
new
BuildPDFJob
(
course
,
project
,
job
);
buildPDFJob
.
jobFunc
(
job
,
done
);
}
const
zipAndGetPDFJob
=
new
ZipJob
(
sldb
,
project_id
,
course
,
after_zip
);
const
zipAndGetPDFJob
=
new
ZipJob
(
sldb
,
project_id
,
course
,
(
zip_details
,
project
,
job
,
done
)
=>
{
setTimeout
(()
=>
after_zip
(
zip_details
,
project
,
job
,
done
),
20000
)
}
);
a
.
define
(
getpdf_task_name
,
opts
,
zipAndGetPDFJob
.
jobFunc
.
bind
(
zipAndGetPDFJob
));
const
zip_task_name
=
`Zip for
${
course
}
`
;
...
...
@@ -66,15 +67,45 @@ process.on('SIGTERM', graceful);
process
.
on
(
'
SIGINT
'
,
graceful
);
a
.
on
(
'
start
'
,
function
(
job
)
{
job
.
attrs
.
status
=
'
running
'
;
job
.
save
()
logger
.
info
(
'
Job %s starting
'
,
job
.
attrs
.
name
);
});
a
.
on
(
'
complete
'
,
function
(
job
)
{
job
.
attrs
.
status
=
'
completed
'
;
job
.
save
()
logger
.
info
(
'
Job %s finished
'
,
job
.
attrs
.
name
);
});
a
.
on
(
'
fail
'
,
function
(
job
)
{
job
.
attrs
.
status
=
'
failed
'
;
job
.
save
()
logger
.
error
(
'
Job %s FAILED
'
,
job
.
attrs
.
name
);
});
// TODO: create a repeated job that runs this to remove old jobs.
export
function
purgeOldJobs
(
job_name
,
callback
)
{
const
max_jobs
=
0
;
a
.
jobs
({
name
:
job_name
},
function
(
err
,
jobs
)
{
console
.
dir
(
jobs
);
jobs
.
sort
((
j1
,
j2
)
=>
(
(
new
Date
(
j2
.
attrs
.
lastFinishedAt
)
-
new
Date
(
j1
.
attrs
.
lastFinishedAt
))
))
logger
.
info
(
`Purge: Got
${
jobs
.
length
}
jobs for job
${
job_name
}
`
);
const
tasks
=
jobs
.
slice
(
max_jobs
).
map
(
(
job
)
=>
{
return
(
cb
)
=>
{
console
.
dir
(
job
);
job
.
remove
(
function
(
err
)
{
if
(
!
err
)
console
.
log
(
'
Purge: Successfully removed job from collection
'
);
cb
();
})
}
});
async
.
series
(
tasks
,
callback
);
});
};
export
{
a
as
agenda
,
tasks
,
sharelatex_config
};
This diff is collapsed.
Click to expand it.
getpdf-server/src/api/getpdf.js
+
16
−
39
View file @
d55b9a97
...
...
@@ -5,8 +5,7 @@ import path from 'path';
import
async
from
'
async
'
;
import
fs
from
'
fs
'
;
import
logger
from
'
../logger
'
;
import
{
agenda
,
tasks
}
from
'
../agenda
'
;
import
{
agenda
,
tasks
,
purgeOldJobs
}
from
'
../agenda
'
;
class
GetPDFRouter
{
constructor
({
config
,
dbs
,
router
})
{
...
...
@@ -53,8 +52,7 @@ class GetPDFRouter {
console
.
dir
(
req
.
params
);
var
job
=
agenda
.
now
(
tasks
.
getpdf
[
req
.
params
.
course_id
].
name
,
{},
(
err
,
j
)
=>
{
logger
.
error
(
err
);
// job.unique
res
.
status
(
200
)
res
.
status
(
201
)
.
json
(
job
);
});
}
...
...
@@ -73,13 +71,13 @@ function getPDFRouter({config, dbs}) {
getpdfRouter
.
newJob
(
req
,
res
);
});
router
.
route
(
'
/
clean
'
)
router
.
route
(
'
/
summary
'
)
.
get
(
function
(
req
,
res
)
{
const
job_name
=
tasks
.
getpdf
[
req
.
params
.
course_id
].
name
;
agenda
.
jobs
({
name
:
job_name
},
function
(
err
,
jobs
)
{
logger
.
info
(
`Got
${
jobs
.
length
}
jobs for job
${
job_name
}
`
);
const
j
=
jobs
.
map
((
job
)
=>
{
delete
job
.
attrs
.
data
;
return
job
}
);
const
j
=
jobs
.
map
((
job
)
=>
{
delete
job
.
attrs
.
data
.
logs
;
return
job
}
);
res
.
status
(
200
)
.
json
(
j
);
});
...
...
@@ -87,42 +85,13 @@ function getPDFRouter({config, dbs}) {
router
.
route
(
'
/purge
'
)
.
get
(
function
(
req
,
res
)
{
const
max_jobs
=
1
;
const
job_name
=
tasks
.
getpdf
[
req
.
params
.
course_id
].
name
;
agenda
.
jobs
({
name
:
job_name
},
function
(
err
,
jobs
)
{
console
.
dir
(
jobs
);
jobs
.
sort
((
j1
,
j2
)
=>
(
(
new
Date
(
j2
.
attrs
.
lastFinishedAt
)
-
new
Date
(
j1
.
attrs
.
lastFinishedAt
))
))
logger
.
info
(
`Purge: Got
${
jobs
.
length
}
jobs for job
${
job_name
}
`
);
const
tasks
=
jobs
.
slice
(
max_jobs
).
map
(
(
job
)
=>
{
return
(
cb
)
=>
{
console
.
dir
(
job
);
job
.
remove
(
function
(
err
)
{
if
(
!
err
)
console
.
log
(
'
Purge: Successfully removed job from collection
'
);
cb
();
})
}
});
async
.
series
(
tasks
,
()
=>
{
purgeOldJobs
(
job_name
,
()
=>
{
res
.
status
(
200
)
.
json
({});
})
});
});
router
.
route
(
'
/cancel
'
)
.
get
(
function
(
req
,
res
)
{
const
job_name
=
tasks
.
getpdf
[
req
.
params
.
course_id
].
name
;
agenda
.
cancel
({
name
:
job_name
},
function
(
err
,
jobs
)
{
// logger.info(`Got ${jobs.length} jobs for job ${job_name}`);
// const j = jobs.map((job) => {delete job.attrs.data; return job} );
res
.
status
(
200
)
.
json
(
err
);
});
});
router
.
route
(
'
/:job_id
'
)
.
get
(
function
(
req
,
res
)
{
...
...
@@ -131,6 +100,14 @@ function getPDFRouter({config, dbs}) {
res
.
status
(
200
)
.
json
(
jobs
);
});
})
.
delete
(
function
(
req
,
res
)
{
const
job_id
=
req
.
params
.
job_id
;
agenda
.
jobs
({
_id
:
ObjectId
(
job_id
)},
function
(
err
,
jobs
)
{
const
delete_result
=
jobs
.
map
(
(
job
)
=>
job
.
remove
()
);
res
.
status
(
200
)
.
json
(
delete_result
);
});
});
return
router
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment