Commit 151fb96f authored by Caleb Weeks's avatar Caleb Weeks

updating log statements. adding exists check before touching

parent 2f971dcf
......@@ -394,9 +394,9 @@ module.exports = function restubFromBlQuery(params, cb){
if(attempt < 60){
sc.post(path, {'bl:touch': (new Date()).getTime() + ""}, (err)=>{
if(!err){
log.info(`Successfully touched ${path} on attempt ${attempt}`);
touchCb();
}else{
log.warning(`Failed to successfully touch ${path} on attempt ${attempt}`);
setTimeout(()=>{touch(path, touchCb, attempt + 1)}, 500);
}
});
......@@ -430,11 +430,22 @@ module.exports = function restubFromBlQuery(params, cb){
};
//we only want to go with the touch approach when we're under a child page
if(_.includes(targetPath, "/jcr:content/")){
//we only want to go with the touch approach when we're under or on a page
if(_.includes(targetPath, "/jcr:content")){
//do a 'touch' to ensure there are no current conflicts
let jcrPath = targetPath.split('/jcr:content')[0] + '/jcr:content';
touch(jcrPath, submitThrottledRequest);
//first ensure the path exists
sc.getSling(`/bin/exists.json?path=${jcrPath}`, (err, data) => {
if (!data || !data.exists) {
console.log(`${jcrPath} doesn't exist. Not touching.`);
//page doesn't exst, can't touch
submitThrottledRequest();
}else{
console.log(`${jcrPath} exists. Touching.`);
//make sure all is good before proceeding
touch(jcrPath, submitThrottledRequest);
}
});
}else{
submitThrottledRequest();
}
......
var _=require("lodash");
var removeBlQuery = /(.*\/bl:q)(\/.*)/;
var log=global.bl.logger.get("bl-edit.query-mapping");
var log=global.bl.logger.get("bl-edit.query-change");
var _path=require("path");
/**
......@@ -16,7 +16,7 @@ exports.process=function(model, $, cb){
var message=$.express.req.body;
var relevantPaths=[];
var queue = global.bl.queues.get("blacklight.edit.mapped-stubs");
console.log("query-change message", message);
log.info("query-change message", message);
_.each(message.updates, (update)=>{
let match=update.path.match(removeBlQuery);
......@@ -28,7 +28,7 @@ exports.process=function(model, $, cb){
if(relevantPaths.length){
console.log("-----------\nQuery change observed:", relevantPaths);
log.info("-----------\nQuery change observed:", relevantPaths);
let tasks={prototype:{}, tasks:[]};
_.each(relevantPaths, (match)=>{
......@@ -40,7 +40,7 @@ exports.process=function(model, $, cb){
queue.makeJob(tasks,(err,job)=>{
if(err){log.error("Couldn't add job to 'mapped-stubs' queue", err);}
else{
console.log("Success adding job to 'mapped-stubs' queue:", job.id);
log.info("Success adding job to 'mapped-stubs' queue:", job.id);
}
});
......
......@@ -20,7 +20,7 @@ exports.process=function(model, $, cb){
var updatedCollectionItems = [];
var queue = global.bl.queues.get("blacklight.edit.mapped-stubs");
var renameQueue = global.bl.queues.get("blacklight.edit.mapped-stubs-rename");
console.log('query-mapping message', message);
log.info('query-mapping message', message);
// console.log("RECIEVED MESSAGE:", JSON.stringify(message,null," "));
......@@ -51,11 +51,11 @@ exports.process=function(model, $, cb){
renameQueue.makeJob(moveTasks,(err,job)=>{
if(err){log.error("Couldn't add job to 'mapped-stubs-rename' queue", err);}
else{
console.log("Success adding job to 'mapped-stubs-rename' queue:", job.id);
log.info("Success adding job to 'mapped-stubs-rename' queue:", job.id);
}
});
}else{
console.log("Query-mapping.js: No renaming in response to observer message.");
log.info("Query-mapping.js: No renaming in response to observer message.");
}
......@@ -123,7 +123,7 @@ exports.process=function(model, $, cb){
var query = {value:{$in:queries}};
var url = "/bin/indexes/query/bl:query?query=" + global.escape(JSON.stringify(query))
SC.getSling(url,{leaveMangledNames:true}, (err, matches)=>{
if(err){console.log("Couldn't query Sling service using Loki protocols", err);}
if(err){log.error("Couldn't query Sling service using Loki protocols", err);}
else{
restubMatches(matches);
}
......@@ -134,7 +134,7 @@ exports.process=function(model, $, cb){
let rootsPredicate = _.map(queryRoots, (root)=> {return ` ISDESCENDANTNODE([${root}]) `}).join(' OR ');
var url = `/content.custom-query.json?statement=SELECT * FROM [nt:base] WHERE [bl:query] IN("${queries.join('" ,"')}") AND (${rootsPredicate})&queryType=JCR-SQL2&property=bl:query@Named[value]`;
SC.getSling(url,{leaveMangledNames:true}, (err, matches)=>{
if(err){console.log("Couldn't query Sling service", err);}
if(err){log.error("Couldn't query Sling service", err);}
else{
_.each(matches, (result)=>{result.path=result['jcr:path'] + '/bl:query'; delete result['jcr:path']; });
restubMatches(matches);
......@@ -151,7 +151,7 @@ exports.process=function(model, $, cb){
var tasks={prototype:{}, tasks:[]}
_.each(matches,(match)=>{
var isBlQuery = (match && match.path) ? match.path.match(removeBlQuery) : null;
if(!isBlQuery){ console.log("Unexpected query result format:", match); return false;}
if(!isBlQuery){ log.error("Unexpected query result format:", match); return false;}
else{
tasks.tasks.push({
path:match.path,
......@@ -165,11 +165,11 @@ exports.process=function(model, $, cb){
queue.makeJob(tasks,(err,job)=>{
if(err){log.error("Couldn't add job to 'mapped-stubs' queue", err);}
else{
console.log("Success adding job to 'mapped-stubs' queue:", job.id);
log.info("Success adding job to 'mapped-stubs' queue:", job.id);
}
});
}else{
console.log("Query-mapping.js: No new restubbing in response to observer message.");
log.info("Query-mapping.js: No new restubbing in response to observer message.");
}
}
......
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