Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xanadu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Mahendra Patel
xanadu
Commits
3455f6d9
Commit
3455f6d9
authored
4 years ago
by
Nilanjan Daw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a new Test Isolation Executor
parent
8217acb1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
108 additions
and
0 deletions
+108
-0
dispatch_system/dispatch_manager/repository/worker_env/envTest.js
..._system/dispatch_manager/repository/worker_env/envTest.js
+108
-0
No files found.
dispatch_system/dispatch_manager/repository/worker_env/envTest.js
0 → 100644
View file @
3455f6d9
'
use strict
'
;
const
express
=
require
(
'
express
'
)
let
request
=
require
(
'
request
'
)
const
process
=
require
(
'
process
'
)
const
app
=
express
()
let
port
=
5000
,
resource_id
,
functionHash
,
runtime
,
idleTime
=
60
,
flagFirstRequest
=
true
let
waitTime
resource_id
=
process
.
argv
[
2
]
functionHash
=
process
.
argv
[
3
]
port
=
process
.
argv
[
4
]
runtime
=
process
.
argv
[
5
]
request
=
request
.
defaults
({
headers
:
{
'
x-resource-id
'
:
resource_id
}
});
let
kafka
=
require
(
'
kafka-node
'
),
Producer
=
kafka
.
Producer
,
client
=
new
kafka
.
KafkaClient
({
kafkaHost
:
process
.
argv
[
6
],
autoConnect
:
true
}),
producer
=
new
Producer
(
client
)
app
.
use
(
express
.
json
());
app
.
use
(
express
.
urlencoded
({
extended
:
true
}));
let
lastRequest
=
Date
.
now
(),
totalRequest
=
0
app
.
post
(
'
/serverless/function/execute/
'
,
(
req
,
res
)
=>
{
console
.
log
(
"
asd
"
);
if
(
flagFirstRequest
)
{
waitTime
=
Date
.
now
()
-
waitTime
flagFirstRequest
=
false
producer
.
send
(
[{
topic
:
"
test
"
,
messages
:
JSON
.
stringify
({
functionHash
,
portExternal
:
port
,
runtime
,
resource_id
,
entity_id
:
process
.
pid
,
total_request
:
totalRequest
,
wait_time
:
waitTime
}),
"
status
"
:
true
}],
()
=>
{
})
}
let
payload
=
req
.
body
lastRequest
=
Date
.
now
()
totalRequest
++
executor
(
payload
).
then
((
result
)
=>
{
res
.
json
(
result
)
idleTime
=
0
})
})
app
.
post
(
'
/serverless/function/timeout
'
,
(
req
,
res
)
=>
{
console
.
log
(
req
.
body
);
let
idleTime
=
req
.
body
.
timeout
console
.
log
(
"
Idle time set to:
"
,
idleTime
);
res
.
json
({
status
:
"
success
"
})
})
async
function
executor
(
payload
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
resolve
({})
})
}
app
.
listen
(
port
,
()
=>
{
console
.
log
(
`Resource
${
resource_id
}
Server listening on port
${
port
}
!`
)
producer
.
send
(
[{
topic
:
"
deployed
"
,
messages
:
JSON
.
stringify
({
functionHash
,
portExternal
:
port
,
runtime
,
resource_id
,
entity_id
:
process
.
pid
}),
"
status
"
:
true
}],
()
=>
{
})
waitTime
=
Date
.
now
()
})
function
shouldDie
()
{
if
(
Date
.
now
()
-
lastRequest
>
idleTime
*
1000
)
{
let
message
=
JSON
.
stringify
({
functionHash
,
portExternal
:
port
,
runtime
,
resource_id
,
entity_id
:
process
.
pid
,
total_request
:
totalRequest
,
wait_time
:
waitTime
})
console
.
log
(
"
Idle for too long. Exiting
"
);
producer
.
send
(
[
{
topic
:
"
removeWorker
"
,
messages
:
message
}
],
(
err
,
data
)
=>
{
if
(
err
)
console
.
log
(
err
);
console
.
log
(
"
Ending worker for function
"
,
functionHash
,
"
resource_id
"
,
resource_id
);
process
.
exit
(
0
)
})
}
}
setInterval
(
shouldDie
,
1000
);
\ No newline at end of file
This diff is collapsed.
Click to expand it.
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