Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
signalboost
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
110
Issues
110
List
Boards
Labels
Service Desk
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
team-friendo
signalboost
Commits
9253a7ae
Verified
Commit
9253a7ae
authored
Sep 10, 2020
by
aguestuser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[215] make all jobs cancellable (and cancel them in .stop())
parent
51e6a532
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
17 deletions
+27
-17
app/index.js
app/index.js
+8
-2
app/jobs.js
app/jobs.js
+18
-4
test/unit/jobs.spec.js
test/unit/jobs.spec.js
+1
-11
No files found.
app/index.js
View file @
9253a7ae
...
...
@@ -7,6 +7,7 @@ const app = {
socketPool
:
null
,
api
:
null
,
metrics
:
null
,
jobs
:
null
,
}
app
.
run
=
async
({
db
,
socketPool
,
api
,
metrics
,
jobs
,
signal
})
=>
{
...
...
@@ -40,7 +41,7 @@ app.run = async ({ db, socketPool, api, metrics, jobs, signal }) => {
logger
.
log
(
`...created metrics registry!`
)
logger
.
log
(
'
Running startup jobs...
'
)
a
wait
jobsService
.
run
().
catch
(
logger
.
fatalError
)
a
pp
.
jobs
=
jobsService
.
run
().
catch
(
logger
.
fatalError
)
logger
.
log
(
'
...ran startup jobs!
'
)
logger
.
log
(
'
Starting signal service...
'
)
...
...
@@ -54,7 +55,12 @@ app.run = async ({ db, socketPool, api, metrics, jobs, signal }) => {
app
.
stop
=
async
()
=>
{
const
{
logger
}
=
require
(
'
./util
'
)
logger
.
log
(
'
Shutting down signalboost...
'
)
await
Promise
.
all
([
app
.
socketPool
.
stop
(),
app
.
db
.
stop
(),
app
.
api
.
stop
()])
await
Promise
.
all
([
()
=>
app
.
socketPool
.
stop
(),
()
=>
app
.
db
.
stop
(),
()
=>
app
.
api
.
stop
(),
()
=>
app
.
jobs
.
stop
(),
])
logger
.
log
(
'
...Signalboost shut down!
'
)
}
...
...
app/jobs.js
View file @
9253a7ae
...
...
@@ -5,11 +5,18 @@ const smsSenderRepository = require('./db/repositories/smsSender')
const
hotlineMessageRepository
=
require
(
'
./db/repositories/hotlineMessage
'
)
const
diagnostics
=
require
(
'
./diagnostics
'
)
const
util
=
require
(
'
./util
'
)
const
{
values
}
=
require
(
'
lodash
'
)
const
{
job
:
{
healthcheckInterval
,
inviteDeletionInterval
,
recycleInterval
,
signaldStartupTime
},
signal
:
{
diagnosticsPhoneNumber
},
}
=
require
(
'
./config
'
)
const
cancelations
=
{
deleteInvitesJob
:
null
,
recycleJob
:
null
,
healtcheckJob
:
null
,
}
const
run
=
async
()
=>
{
logger
.
log
(
'
--- Running startup jobs...
'
)
...
...
@@ -38,14 +45,14 @@ const run = async () => {
*****************/
logger
.
log
(
'
----- Launching invite scrubbing job...
'
)
util
.
repeatEvery
(
cancelations
.
deleteInvitesJob
=
util
.
repeatUntilCancelled
(
()
=>
inviteRepository
.
deleteExpired
().
catch
(
logger
.
error
),
inviteDeletionInterval
,
)
logger
.
log
(
'
----- Launched invite scrubbing job.
'
)
logger
.
log
(
'
---- Launching recycle request processing job...
'
)
util
.
repeatEvery
(
cancelations
.
recycleJob
=
util
.
repeatUntilCancelled
(
()
=>
phoneNumberRegistrar
.
processRecycleRequests
().
catch
(
logger
.
error
),
recycleInterval
,
)
...
...
@@ -54,13 +61,20 @@ const run = async () => {
logger
.
log
(
'
---- Launching healthcheck job...
'
)
const
launchHealthchecks
=
async
()
=>
{
await
util
.
wait
(
signaldStartupTime
)
util
.
repeatEvery
(()
=>
diagnostics
.
sendHealthchecks
().
catch
(
logger
.
error
),
healthcheckInterval
)
cancelations
.
healtcheckJob
=
util
.
repeatUntilCancelled
(
()
=>
diagnostics
.
sendHealthchecks
().
catch
(
logger
.
error
),
healthcheckInterval
,
)
}
if
(
diagnosticsPhoneNumber
)
launchHealthchecks
()
logger
.
log
(
'
---- Launched healthcheck job...
'
)
logger
.
log
(
'
--- Startup jobs complete!
'
)
logger
.
log
(
'
--- Registrar running!
'
)
return
{
stop
}
}
module
.
exports
=
{
run
}
const
stop
=
()
=>
values
(
cancelations
).
forEach
(
fn
=>
fn
())
module
.
exports
=
{
run
,
stop
}
test/unit/jobs.spec.js
View file @
9253a7ae
...
...
@@ -20,17 +20,6 @@ describe('jobs service', () => {
processRecycleRequestsStub
,
sendHealthchecksStub
/****
* TODO(aguestuser|2020-09-10):
*
* The fact that this suite kicks of long-running recurring jobs but never
* cancels them causes other unit tests to fail non-determinitically, because they
* asserting on the same functions that are called repeatedly in this suite.
*
* If this gets annoying enough, we should likely figure out a `jobs.stop()` function
* that cancels all the `repeatEvery` calls a
**/
describe
(
'
running the service
'
,
()
=>
{
let
originalReregisterValue
=
process
.
env
.
REREGISTER_ON_STARTUP
before
(
async
()
=>
{
...
...
@@ -59,6 +48,7 @@ describe('jobs service', () => {
after
(()
=>
{
process
.
env
.
REREGISTER_ON_STARTUP
=
originalReregisterValue
sinon
.
restore
()
jobs
.
stop
()
})
describe
(
'
one-off jobs
'
,
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment