Skip to content

Commit

Permalink
Fix ci formatting failures
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Steed committed Oct 14, 2019
1 parent 4cb0aee commit 1b0e66b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 41 deletions.
10 changes: 5 additions & 5 deletions action/alarmWebAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function main(params) {
additionalData: common.constructObject(params.additionalData),
};
var triggerID = new Database().constructTriggerID(getDBConfig(params), triggerData);

var workers = params.workers instanceof Array ? params.workers : [];
var deleteAfterFireArray = ['false', 'true', 'rules'];
var db;
Expand Down Expand Up @@ -149,7 +149,7 @@ function main(params) {
return getDatabase(getDBConfig(params));
})
.then((database) => {
db = database
db = database;
return db.getWorkerID(workers);
})
.then((worker) => {
Expand Down Expand Up @@ -178,7 +178,7 @@ function main(params) {
return getDatabase(getDBConfig(params));
})
.then((database) => {
db = database
db = database;
return db.getTrigger(triggerID);
})
.then(doc => {
Expand Down Expand Up @@ -231,7 +231,7 @@ function main(params) {
return getDatabase(getDBConfig(params));
})
.then((database) => {
db = database
db = database;
return db.getTrigger(triggerID);
})
.then(trigger => {
Expand Down Expand Up @@ -352,7 +352,7 @@ function main(params) {
return getDatabase(getDBConfig(params));
})
.then((database) => {
db = database
db = database;
return db.getTrigger(triggerID);
})
.then(trigger => {
Expand Down
69 changes: 35 additions & 34 deletions action/lib/cosmosdb.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const common = require('./common');

module.exports = function(endpoint, masterKey) {
var DocumentClient = require('documentdb').DocumentClient;
var client = new DocumentClient(endpoint, {masterKey: masterKey});

this.client = client;
var utilsDB = this;

this.init = function(databaseName, collectionName) {
console.log("cosmosdb.init");
let querySpec = {
Expand All @@ -44,7 +45,7 @@ module.exports = function(endpoint, masterKey) {
});
});
};

//get collection in cosmosdb terminology
this.getDatabase = function(collectionName) {
console.log(`cosmosdb.getDatabase:`, collectionName);
Expand All @@ -70,12 +71,12 @@ module.exports = function(endpoint, masterKey) {
utilsDB.collectionLink = results[0]._self;
resolve(results);
}

}
});
});
};

//create collection in cosmosdb terminology
this.createDatabase = function(collectionName) {
console.log(`cosmosdb.createDatabase:`,collectionName);
Expand All @@ -93,24 +94,24 @@ module.exports = function(endpoint, masterKey) {
});
});
};

this.getWorkerID = function(availabeWorkers) {

return new Promise((resolve, reject) => {
var workerID = availabeWorkers[0] || 'worker0';
resolve(workerID);
});
};

this.createTrigger = function(triggerID, newTrigger) {
console.log(`cosmosdb.createTrigger:`, triggerID);
if(!newTrigger.id) {
console.log("add id to doc");
newTrigger.id = triggerID;
}

return new Promise(function(resolve, reject) {

client.createDocument(utilsDB.collectionLink, newTrigger, function(err, document) {
if(err) {
console.error(`cosmosdb.createTrigger failed:`, err);
Expand All @@ -122,15 +123,15 @@ module.exports = function(endpoint, masterKey) {
});
});
};

this.getTrigger = function(triggerID, retry = true) {
console.log(`cosmosdb.getTrigger:`, triggerID);
return new Promise(function(resolve, reject) {
let querySpec = {
query: 'SELECT * FROM root r WHERE r.id = @id',
parameters: [{ name: '@id', value: triggerID }]
};

client.queryDocuments(utilsDB.collectionLink, querySpec).toArray(function(err, results) {
if (err) {
if (retry) {
Expand All @@ -145,7 +146,7 @@ module.exports = function(endpoint, masterKey) {
reject(common.sendError(err.statusCode, 'could not find trigger ' + triggerID + ' in the database'));
}
}

if(results.length == 0)
resolve();
else {
Expand All @@ -155,7 +156,7 @@ module.exports = function(endpoint, masterKey) {
});
});
};

this.updateTrigger = function(triggerID, trigger, params, retryCount) {
console.log(`cosmosdb.updateTrigger:`, triggerID);
if (retryCount === 0) {
Expand All @@ -168,7 +169,7 @@ module.exports = function(endpoint, masterKey) {
};
trigger.status = status;
}

return new Promise(function(resolve, reject) {
utilsDB.getTrigger(triggerID)
.then((doc) => {
Expand Down Expand Up @@ -197,15 +198,15 @@ module.exports = function(endpoint, masterKey) {
});
});
};

this.disableTrigger = function(triggerID, trigger, retryCount, crudMessage) {
console.log(`cosmosdb.disableTrigger:`, triggerID);
if (retryCount === 0) {
//check if it is already disabled
if (trigger.status && trigger.status.active === false) {
return Promise.resolve(triggerID);
}

var message = `Automatically disabled trigger while ${crudMessage}`;
var status = {
'active': false,
Expand All @@ -214,10 +215,10 @@ module.exports = function(endpoint, masterKey) {
};
trigger.status = status;
}

return utilsDB.updateTrigger(triggerID, trigger, {}, retryCount);
};

this.deleteTrigger = function(triggerID) {
console.log(`cosmosdb.deleteTrigger`, triggerID);
return new Promise(function(resolve, reject) {
Expand Down
4 changes: 2 additions & 2 deletions provider/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ module.exports = function(logger, triggerDB, redisClient) {
logger.error(method, 'trigger', triggerIdentifier, 'has been disabled due to status code:', response.statusCode);
}
else {
logger.info(method, 'will create trigger')
logger.info(method, 'will create trigger');
createTrigger(triggerIdentifier, doc)
.then(cachedTrigger => {
self.triggers[triggerIdentifier] = cachedTrigger;
Expand All @@ -350,7 +350,7 @@ module.exports = function(logger, triggerDB, redisClient) {
logger.error(method, 'could not get latest state from database', err);
});
};

function setupFollow(seq) {
var method = 'setupFollow';

Expand Down

0 comments on commit 1b0e66b

Please sign in to comment.