Skip to content

Commit

Permalink
Fixed subscription issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Nov 20, 2018
1 parent 3e30816 commit 0a36f71
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
14 changes: 9 additions & 5 deletions openeo/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = class FilesAPI {
.then(files => {
var output = files.map(file => {
return {
name: path.relative(this.getUserFolder(req.user._id), file.path),
name: this.getFileName(req.user._id, file.path),
size: file.stat.size,
modified: file.stat.mtime.toISOString()
}
Expand Down Expand Up @@ -107,10 +107,10 @@ module.exports = class FilesAPI {
stream.end();
const payload = {
user_id: req.user._id,
path: p.replace('storage/user_files/' + req.user._id + '/', ''),
path: this.getFileName(req.user._id, p),
action: fileExists ? 'updated' : 'created'
};
req.api.subscriptions.publish(req, 'openeo.files', payload, payload);
req.api.subscriptions.publish(req.user._id, 'openeo.files', payload, payload);
res.send(204);
return next();
});
Expand All @@ -137,10 +137,10 @@ module.exports = class FilesAPI {
.then(() => {
const payload = {
user_id: req.user._id,
path: p.replace('storage/user_files/'+req.user._id+'/', ''),
path: this.getFileName(req.user._id, p),
action: 'deleted'
};
req.api.subscriptions.publish(req, 'openeo.files', payload, payload);
req.api.subscriptions.publish(req.user._id, 'openeo.files', payload, payload);
res.send(204);
return next();
})
Expand Down Expand Up @@ -192,6 +192,10 @@ module.exports = class FilesAPI {
return null;
}

getFileName(user_id, p) {
return path.relative(this.getUserFolder(user_id), p);
}

isFile(path) {
return fse.stat(path).then(stat => {
if (stat.isFile()) {
Expand Down
2 changes: 1 addition & 1 deletion openeo/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ module.exports = class JobsAPI {
parameters: processParams
};
}
req.api.subscriptions.publish(req, "openeo.jobs.debug", params, payload);
req.api.subscriptions.publish(req.user._id, "openeo.jobs.debug", params, payload);
} catch (e) {
console.log(e);
}
Expand Down
14 changes: 4 additions & 10 deletions openeo/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SubscriptionConnection {
isSubscribed(topic, params) {
params.topic = topic;
var hash = Utils.hashJSON(params);
return (topics.get(hash) !== 'undefined');
return (this.topics.get(hash) !== 'undefined');
}

sendWelcomeMessage() {
Expand All @@ -50,7 +50,9 @@ class SubscriptionConnection {
payload: payload
};

this.connection.send(JSON.stringify(message));
if (this.connection.readyState === this.connection.OPEN) {
this.connection.send(JSON.stringify(message));
}
}

sendMessageIfSubscribed(topic, params, payload) {
Expand Down Expand Up @@ -80,14 +82,6 @@ module.exports = class SubscriptionsAPI {
beforeServerStart(server) {
server.addEndpoint('get', '/subscription', this.getSubscription.bind(this));

// ToDo: Remove test topic once this is a bit more stable
if (global.server.config.debug) {
this.registerTopic("openeo.test");
setInterval(() => {
this.broadcast("openeo.test", {}, {message: 'test'})
}, 1000);
}

return Promise.resolve();
}

Expand Down

0 comments on commit 0a36f71

Please sign in to comment.