Skip to content

Commit

Permalink
Merge branch 'master' into more-queue-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
niekcandaele committed Jun 20, 2020
2 parents dcf336a + d3b0208 commit bd1c957
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 41 deletions.
3 changes: 2 additions & 1 deletion api/helpers/get-queue-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ module.exports = {
return exits.success({
on: function () { },
process: function () { },
empty: function () { }
empty: function () { },
add: function() {}
});
}
const queue = new Bull(
Expand Down
3 changes: 3 additions & 0 deletions api/hooks/discordChatBridge/chatBridgeChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ class ChatBridgeChannel {

async sendRichDisconnectedMessageToDiscord(disconnectedMsg) {
let disconnectedPlayer = disconnectedMsg.player;
if (!disconnectedPlayer) {
return;
}

let gblBans = await BanEntry.find({
steamId: disconnectedPlayer.steamId
Expand Down
10 changes: 6 additions & 4 deletions api/hooks/sdtdLogs/LoggingObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class LoggingObject extends EventEmitter {
};

async init(ms = sails.config.custom.logCheckInterval) {

if (!ms) {
ms = 3000;
}
Expand Down Expand Up @@ -166,14 +165,17 @@ class LoggingObject extends EventEmitter {
);
}

async setLastLogLine() {
async setLastLogLine(lastLogLine) {
const server = await SdtdServer.findOne(this.serverId)
const webUIUpdate = await SdtdApi.getWebUIUpdates(SdtdServer.getAPIConfig(server));
const lastLogLine = parseInt(webUIUpdate.newlogs) + 1;
if (!lastLogLine && lastLogLine !== 0) {
const webUIUpdate = await SdtdApi.getWebUIUpdates(SdtdServer.getAPIConfig(server));
lastLogLine = parseInt(webUIUpdate.newlogs) + 1;
}
await sails.helpers.redis.set(
`sdtdserver:${this.serverId}:sdtdLogs:lastLogLine`,
lastLogLine
);
this.lastLogLine = lastLogLine;
this.emptyResponses = 0;
return lastLogLine;
}
Expand Down
20 changes: 1 addition & 19 deletions api/hooks/sdtdLogs/logProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ const handleLogLine = require("./handleLogLine");

module.exports = async function(job) {
const resultLogs = [];
// Get latest log line from Redis
let lastLogLine = parseInt(
await sails.helpers.redis.get(
`sdtdserver:${job.data.server.id}:sdtdLogs:lastLogLine`
)
);

let lastLogLine = job.data.lastLogLine;
// If latest log line is not found, get it from the server
if (!lastLogLine) {
const webUIUpdate = await sails.helpers.sdtdApi.getWebUIUpdates(SdtdServer.getAPIConfig(job.data.server));
Expand All @@ -22,12 +16,6 @@ module.exports = async function(job) {
// Adjust latest log line based on new logs we got
lastLogLine = lastLogLine + newLogs.entries.length;

// Set latest log line in Redis
await sails.helpers.redis.set(
`sdtdserver:${job.data.server.id}:sdtdLogs:lastLogLine`,
lastLogLine
);

// Parse these logs into usable data
let index = -1;
for (const line of newLogs.entries) {
Expand All @@ -46,12 +34,6 @@ module.exports = async function(job) {
}
}

// Set last success date in Redis
await sails.helpers.redis.set(
`sdtdserver:${job.data.server.id}:sdtdLogs:lastSuccess`,
Date.now()
);

return Promise.resolve({
serverId: job.data.server.id,
lastLogLine,
Expand Down
8 changes: 4 additions & 4 deletions test/integration/cron-job/cron.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ var expect = require("chai").expect;

describe('POST /api/sdtdserver/cron', function () {

it('should return 200 with valid info', function (done) {
supertest(sails.hooks.http.app)
it('should return 200 with valid info', async function () {
const response = await supertest(sails.hooks.http.app)
.post('/api/sdtdserver/cron')
.send({
serverId: 1,
command: 'help',
temporalValue: '0 */6 * * *'
})
.expect('Content-Type', /json/)
.expect(200, done);
expect(response.statusCode).to.be.eql(200);
expect(response.header['content-type']).to.include('json');
});
it('should return 400 when command or temporal value is not given', function (done) {
supertest(sails.hooks.http.app)
Expand Down
3 changes: 1 addition & 2 deletions test/integration/hooks/sdtdLogs/logProcessor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ const logProcessor = require("../../../../api/hooks/sdtdLogs/logProcessor");

describe('logProcessor', function () {
it('Confirm able to fetch log messages', async function () {
sails.cache[`sdtdserver:${sails.testServer.id}:sdtdLogs:lastLogLine`] = 1100;
sinon.stub(sails.helpers.sdtdApi, "getWebUIUpdates").callsFake(async function () {
return {
newlogs: 1100
newlogs: 1099
}
});
sinon.stub(sails.helpers.sdtdApi, "getLog").callsFake(async function () {
Expand Down
19 changes: 8 additions & 11 deletions test/integration/player-teleport/playerTeleport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,16 @@ describe('Player teleports', function () {
newTeleport = _.omit(newTeleport, 'id');
let requestOptions = newTeleport;
requestOptions.id = testTeleports[0].id;
return supertest(sails.hooks.http.app)
.post('/api/teleport')
.send(requestOptions)
.expect(async function (res) {
let record = await PlayerTeleport.findOne(testTeleports[0]);
return expect(record).to.be.eq(requestOptions);
})
.expect(200)
.expect('Content-Type', /json/);
const res = await supertest(sails.hooks.http.app).post('/api/teleport').send(requestOptions);
expect(res.statusCode).to.equal(200);
expect(res.headers['content-type']).to.include('json');

let record = await PlayerTeleport.findOne(testTeleports[0].id);
expect(record).to.eql(requestOptions);
});

it('should return 400 when id is not given', function () {
return supertest(sails.hooks.http.app)
it('should return 400 when id is not given', async function () {
await supertest(sails.hooks.http.app)
.post('/api/teleport')
.expect(400);
});
Expand Down

0 comments on commit bd1c957

Please sign in to comment.