Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pubsweet
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien Tremblay McLellan
pubsweet
Commits
188f7940
Commit
188f7940
authored
6 years ago
by
Jure
Browse files
Options
Downloads
Patches
Plain Diff
feat: working job roundtrip and test
parent
6f7a0cc4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/server/src/jobs/index.js
+3
-14
3 additions, 14 deletions
packages/server/src/jobs/index.js
packages/server/test/jobs/jobs_test.js
+28
-8
28 additions, 8 deletions
packages/server/test/jobs/jobs_test.js
with
31 additions
and
22 deletions
packages/server/src/jobs/index.js
+
3
−
14
View file @
188f7940
...
...
@@ -4,32 +4,21 @@ const logger = require('@pubsweet/logger')
const
db
=
require
(
'
../db
'
)
const
alphabet
=
stringNumber
=>
{
const
number
=
Number
(
stringNumber
)
if
(
number
>
25
)
{
throw
new
Error
(
'
Number too big to be converted to alphabet
'
)
}
return
'
abcdefghijklmnopqrstuvwxyz
'
.
split
(
''
)[
Number
(
stringNumber
)]
}
const
dbAdapter
=
{
executeSql
:
(
sql
,
parameters
=
[])
=>
{
try
{
// This is needed to replace pg-boss' $1, $2 arguments
// into knex's :val, :val2 style.
const
replacedSql
=
sql
.
replace
(
/
\$(\d
+
)\b
/g
,
(
_
,
number
)
=>
`:
${
alphabet
(
number
)}
`
,
)
const
replacedSql
=
sql
.
replace
(
/
\$(\d
+
)\b
/g
,
(
_
,
number
)
=>
`:
${
number
}
`
)
const
parametersObject
=
{}
parameters
.
forEach
(
(
value
,
index
)
=>
(
parametersObject
[
`
${
alphabet
(
index
+
1
)
}
`
]
=
value
),
(
value
,
index
)
=>
(
parametersObject
[
`
${
index
+
1
}
`
]
=
value
),
)
return
db
.
raw
(
replacedSql
,
parametersObject
)
}
catch
(
err
)
{
return
logger
.
error
(
'
Error querying database
'
,
err
.
message
)
return
logger
.
error
(
'
Error querying database
:
'
,
err
.
message
)
}
},
}
...
...
This diff is collapsed.
Click to expand it.
packages/server/test/jobs/jobs_test.js
+
28
−
8
View file @
188f7940
const
jobs
=
require
(
'
../../src/jobs
'
)
const
someHandler
=
async
job
=>
// console.log('HERE I AM WITH', job)
'
victory
'
const
someHandler
=
async
job
=>
{
expect
(
job
.
data
.
param
).
toEqual
(
'
aThing
'
)
return
Promise
.
resolve
({
thing
:
'
someOtherThing
'
})
}
describe
(
'
jobs
'
,
()
=>
{
it
(
'
should connect
'
,
async
()
=>
{
const
jobthing
=
await
jobs
()
let
jobQueue
await
jobthing
.
publish
(
'
some-queue
'
,
{
param1
:
'
1
'
})
// console.log(`created ${jobId}`)
beforeAll
(
async
()
=>
{
jobQueue
=
await
jobs
()
})
it
(
'
submits a job, runs it, and notifies on completion
'
,
async
done
=>
{
const
queueName
=
'
aJobQueue
'
// Subscribe to the job queue with an async handler
await
jobQueue
.
subscribe
(
queueName
,
someHandler
)
await
jobthing
.
subscribe
(
'
some-queue
'
,
someHandler
)
// Add a job to the queue
await
jobQueue
.
publish
(
queueName
,
{
param
:
'
aThing
'
})
// Be notified on job completion with job result
await
jobQueue
.
onComplete
(
queueName
,
job
=>
{
try
{
expect
(
job
.
data
.
response
).
toEqual
({
thing
:
'
someOtherThing
'
})
done
()
}
catch
(
e
)
{
done
.
fail
(
e
)
}
})
})
afterAll
(
async
()
=>
jobQueue
.
stop
())
})
This diff is collapsed.
Click to expand it.
Preview
0%
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