Commit 6ddbd13c authored by nilanjandaw's avatar nilanjandaw

decoupling daemons almost done

Issue with file server remains, unable to download file from master node
parent df51f208
......@@ -12,19 +12,21 @@ const client = mqtt.connect('mqtt://localhost')
const app = express()
const libSupport = require('./lib')
// const secret = require('../secrets.json')
// const db = require('nano')(`http://${secret.dispatched_db_username}:${secret.dispatched_db_password}@localhost:5984/dispatched`)
let db = new Map()
app.use(morgan('combined'))
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
const file_path = __dirname + "/repository"
app.use('/repository', express.static(file_path));
app.use(fileUpload())
const node_id = "20sez54hq8"
const WINDOW_SIZE = 1
const port = 8080
let requestQueue = []
const node_id = "20sez54hq8"
const WINDOW_SIZE = 10
const port = 8080
app.post('/serverless/deploy', (req, res) => {
......@@ -33,7 +35,7 @@ app.post('/serverless/deploy', (req, res) => {
let functionHash = file.md5
file.mv(__dirname + "/test/" + functionHash, function (err) {
file.mv(file_path + functionHash, function (err) {
if (err) {
console.log(err);
res.send("error").status(400)
......@@ -117,7 +119,8 @@ app.post('/serverless/execute/:id', (req, res) => {
function dispatch() {
for (let i = 0; i < WINDOW_SIZE; i++) {
let lookbackWindow = Math.min(WINDOW_SIZE, requestQueue.length)
for (let i = 0; i < lookbackWindow; i++) {
let {req, res} = requestQueue.shift()
let runtime = req.body.runtime
let functionHash = req.params.id
......@@ -145,6 +148,7 @@ client.on('message', function (topic, message) {
"status": "success",
"reply": message.result
})
db.delete(message.function_id)
}
})
......@@ -152,4 +156,6 @@ app.listen(port, () => console.log(`Server listening on port ${port}!`))
client.on('connect', function () {
client.subscribe("response")
})
\ No newline at end of file
})
setInterval(dispatch, 1000);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment