Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
augustctl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
augustctl
Commits
1a49e8f9
Verified
Commit
1a49e8f9
authored
8 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Utility to disconnect from lock and clear its caches
parent
316b1078
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server.js
+15
-13
15 additions, 13 deletions
server.js
with
15 additions
and
13 deletions
server.js
+
15
−
13
View file @
1a49e8f9
...
@@ -26,7 +26,7 @@ app.use( morgan( DEBUG ? 'dev' : 'combined' ) );
...
@@ -26,7 +26,7 @@ app.use( morgan( DEBUG ? 'dev' : 'combined' ) );
* UTILITIES
* UTILITIES
*/
*/
// Default return arguments
// Default return arguments
var
ret
=
{
var
ret
=
{
'
status
'
:
-
1
,
'
status
'
:
-
1
,
'
ret
'
:
''
,
'
ret
'
:
''
,
...
@@ -47,7 +47,7 @@ function statusStringtoInt( status ) {
...
@@ -47,7 +47,7 @@ function statusStringtoInt( status ) {
}
}
// Clear cached routes
// Clear cached routes
function
clear
_c
aches
(
lockName
)
{
function
clear
C
aches
(
lockName
)
{
apicache
.
clear
(
'
/api/status/
'
+
lockName
);
apicache
.
clear
(
'
/api/status/
'
+
lockName
);
apicache
.
clear
(
'
/api/lock/
'
+
lockName
);
apicache
.
clear
(
'
/api/lock/
'
+
lockName
);
apicache
.
clear
(
'
/api/unlock/
'
+
lockName
);
apicache
.
clear
(
'
/api/unlock/
'
+
lockName
);
...
@@ -55,6 +55,12 @@ function clear_caches( lockName ) {
...
@@ -55,6 +55,12 @@ function clear_caches( lockName ) {
return
true
;
return
true
;
}
}
// Reset lock connection
function
disconnectAndClear
(
lockName
)
{
lock
.
disconnect
();
clearCaches
(
lockName
);
}
/**
/**
* ROUTES
* ROUTES
*/
*/
...
@@ -64,7 +70,7 @@ app.get( '/api/status/:lock_name', cache( '15 seconds' ), function( req, res ) {
...
@@ -64,7 +70,7 @@ app.get( '/api/status/:lock_name', cache( '15 seconds' ), function( req, res ) {
// Parse allowed request arguments
// Parse allowed request arguments
var
lock
=
app
.
get
(
'
lock
'
+
req
.
params
.
lock_name
);
var
lock
=
app
.
get
(
'
lock
'
+
req
.
params
.
lock_name
);
if
(
!
lock
)
{
if
(
!
lock
)
{
clear
_c
aches
(
req
.
params
.
lock_name
);
clear
C
aches
(
req
.
params
.
lock_name
);
res
.
sendStatus
(
400
);
res
.
sendStatus
(
400
);
return
;
return
;
}
}
...
@@ -84,8 +90,7 @@ app.get( '/api/status/:lock_name', cache( '15 seconds' ), function( req, res ) {
...
@@ -84,8 +90,7 @@ app.get( '/api/status/:lock_name', cache( '15 seconds' ), function( req, res ) {
// Perform requested action
// Perform requested action
lock
.
connect
().
then
(
actionFunction
).
catch
(
function
(
err
)
{
lock
.
connect
().
then
(
actionFunction
).
catch
(
function
(
err
)
{
console
.
error
(
err
);
console
.
error
(
err
);
lock
.
disconnect
();
disconnectAndClear
(
req
.
params
.
lock_name
);
clear_caches
(
req
.
params
.
lock_name
);
res
.
sendStatus
(
500
);
res
.
sendStatus
(
500
);
}
);
}
);
}
);
}
);
...
@@ -103,7 +108,7 @@ app.get( '/api/:lock_action(lock|unlock)/:lock_name', cache( '5 seconds' ), func
...
@@ -103,7 +108,7 @@ app.get( '/api/:lock_action(lock|unlock)/:lock_name', cache( '5 seconds' ), func
var
lockName
=
req
.
params
.
lock_name
,
var
lockName
=
req
.
params
.
lock_name
,
lock
=
app
.
get
(
'
lock
'
+
lockName
);
lock
=
app
.
get
(
'
lock
'
+
lockName
);
if
(
!
lock
)
{
if
(
!
lock
)
{
clear
_c
aches
(
lockName
);
clear
C
aches
(
lockName
);
res
.
sendStatus
(
400
);
res
.
sendStatus
(
400
);
return
;
return
;
}
}
...
@@ -130,16 +135,14 @@ app.get( '/api/:lock_action(lock|unlock)/:lock_name', cache( '5 seconds' ), func
...
@@ -130,16 +135,14 @@ app.get( '/api/:lock_action(lock|unlock)/:lock_name', cache( '5 seconds' ), func
ret
.
msg
=
"
No change made. Lock was already '
"
+
status
+
"
'.
"
;
ret
.
msg
=
"
No change made. Lock was already '
"
+
status
+
"
'.
"
;
}
}
lock
.
disconnect
();
disconnectAndClear
(
lockName
);
clear_caches
(
lockName
);
res
.
json
(
ret
);
res
.
json
(
ret
);
}
);
}
);
// Perform requested action
// Perform requested action
lock
.
connect
().
then
(
actionFunction
).
catch
(
function
(
err
)
{
lock
.
connect
().
then
(
actionFunction
).
catch
(
function
(
err
)
{
console
.
error
(
err
);
console
.
error
(
err
);
lock
.
disconnect
();
disconnectAndClear
(
lockName
);
clear_caches
(
lockName
);
res
.
sendStatus
(
500
);
res
.
sendStatus
(
500
);
}
);
}
);
}
);
}
);
...
@@ -149,13 +152,12 @@ app.get( '/api/disconnect/:lock_name', function( req, res ) {
...
@@ -149,13 +152,12 @@ app.get( '/api/disconnect/:lock_name', function( req, res ) {
// Parse allowed request arguments
// Parse allowed request arguments
var
lock
=
app
.
get
(
'
lock
'
+
req
.
params
.
lock_name
);
var
lock
=
app
.
get
(
'
lock
'
+
req
.
params
.
lock_name
);
if
(
!
lock
)
{
if
(
!
lock
)
{
clear
_c
aches
(
req
.
params
.
lock_name
);
clear
C
aches
(
req
.
params
.
lock_name
);
res
.
sendStatus
(
400
);
res
.
sendStatus
(
400
);
return
;
return
;
}
}
lock
.
disconnect
();
disconnectAndClear
(
req
.
params
.
lock_name
);
clear_caches
(
req
.
params
.
lock_name
);
res
.
sendStatus
(
204
);
res
.
sendStatus
(
204
);
}
);
}
);
...
...
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