Skip to content
This repository has been archived by the owner on Mar 7, 2018. It is now read-only.

Commit

Permalink
Merge pull request #165 from CatalystCode/trustedsources-final
Browse files Browse the repository at this point in the history
Trustedsources final
  • Loading branch information
Smarker committed Oct 19, 2017
2 parents e47f63d + 9e7d320 commit ede14a7
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 303 deletions.
68 changes: 68 additions & 0 deletions src/clients/appinsights/LoggingClient.js
Expand Up @@ -29,6 +29,12 @@ function logExecuteQueryError() {
});
}

function restartPipelineExtraProps() {
return () => ({
success: 'true'
});
}

function termsExtraProps() {
return () => ({
operation: 'query',
Expand All @@ -37,6 +43,45 @@ function termsExtraProps() {
});
}

function trustedSourcesExtraProps() {
return () => ({
operation: 'query',
table: 'trustedsources',
success: 'true'
});
}

function trustedSourcesExtraMetrics() {
return (graphqlResult) => {
const totalRows = graphqlResult.sources.length;
return {
totalRows
};
};
}

function logNoTrustedSourcesToAdd() {
trackSyncEvent('cassandra', {
client: constants.CLIENTS.cassandra,
operation: 'modify',
table: 'trustedsources',
success: false
}, {
numToMutate: 0
});
}

function logNoTrustedSourcesToRemove() {
trackSyncEvent('cassandra', {
client: constants.CLIENTS.cassandra,
operation: 'remove',
table: 'trustedsources',
success: false
}, {
numToMutate: 0
});
}

function streamsExtraProps() {
return () => ({
operation: 'query',
Expand All @@ -62,6 +107,22 @@ function streamsExtraMetrics() {
};
}

function addTrustedSourcesExtraProps() {
return () => ({
operation: 'modify',
table: 'trustedsources',
success: 'true'
});
}

function removeTrustedSourcesExtraProps() {
return () => ({
operation: 'remove',
table: 'trustedsources',
success: 'true'
});
}

function addKeywordsExtraProps() {
return () => ({
operation: 'modify',
Expand Down Expand Up @@ -149,10 +210,17 @@ module.exports = {
logCassandraClientUndefined,
logNoMutationsDefined,
logExecuteQueryError,
restartPipelineExtraProps,
termsExtraProps,
trustedSourcesExtraProps,
trustedSourcesExtraMetrics,
logNoTrustedSourcesToAdd,
logNoTrustedSourcesToRemove,
streamsExtraProps,
modifyStreamsExtraProps,
streamsExtraMetrics,
addTrustedSourcesExtraProps,
removeTrustedSourcesExtraProps,
addKeywordsExtraProps,
removeKeywordsExtraProps,
keywordsExtraMetrics,
Expand Down
4 changes: 3 additions & 1 deletion src/clients/facebook/FacebookAnalyticsClient.js
Expand Up @@ -6,9 +6,10 @@ const trackDependency = require('../appinsights/AppInsightsClient').trackDepende

const accessToken = process.env.FACEBOOK_AUTH_TOKEN;
const apiUrlBase = process.env.FACEBOOK_API_HOST || 'https://graph.facebook.com';
const facebookApiVersion = 'v2.9';

function buildFeedUri(pageId) {
return `${apiUrlBase}/v2.9/${pageId}/feed`
return `${apiUrlBase}/${facebookApiVersion}/${pageId}/feed`
+ `?access_token=${accessToken}`
+ '&format=json';
}
Expand Down Expand Up @@ -37,6 +38,7 @@ function fetchPageLastUpdatedAt(pageId) {
});
}


module.exports = {
fetchPageLastUpdatedAt: trackDependency(fetchPageLastUpdatedAt, 'Facebook', 'pageLastUpdatedAt')
};
11 changes: 8 additions & 3 deletions src/clients/streaming/StreamingController.js
Expand Up @@ -2,12 +2,16 @@

const Promise = require('promise');
const azure = require('azure-sb');
const trackDependency = require('../appinsights/AppInsightsClient').trackDependency;
const { trackDependency } = require('../appinsights/AppInsightsClient');
const SERVICE_BUS_CONNECTION_STRING = process.env.FORTIS_SB_CONN_STR;

const SERVICE_BUS_CONFIG_QUEUE = process.env.FORTIS_SB_CONFIG_QUEUE || 'configuration';
const SERVICE_BUS_COMMAND_QUEUE = process.env.FORTIS_SB_COMMAND_QUEUE || 'command';

function restartPipeline() {
return notifyUpdate(SERVICE_BUS_COMMAND_QUEUE, { 'dirty': 'streams' });
}

function restartStreaming() {
return notifyUpdate(SERVICE_BUS_COMMAND_QUEUE, { 'dirty': 'streams' });
}
Expand All @@ -31,8 +35,8 @@ function notifyUpdate(queue, properties) {
};

sendQueueMessage(queue, serviceBusMessage)
.then(resolve)
.catch(reject);
.then(resolve(true))
.catch(reject(false));
});
}

Expand All @@ -56,6 +60,7 @@ function sendQueueMessage(queue, serviceBusMessage) {
}

module.exports = {
restartPipeline: trackDependency(restartPipeline, 'ServiceBus', 'send'),
restartStreaming: trackDependency(restartStreaming, 'ServiceBus', 'send'),
notifyWatchlistUpdate: trackDependency(notifyWatchlistUpdate, 'ServiceBus', 'send'),
notifyBlacklistUpdate: trackDependency(notifyBlacklistUpdate, 'ServiceBus', 'send'),
Expand Down
1 change: 1 addition & 0 deletions src/resolvers-cassandra/Messages/index.js
Expand Up @@ -5,6 +5,7 @@ const queries = require('./queries');

module.exports = {
publishEvents: mutations.publishEvents,
restartPipeline: mutations.restartPipeline,

byLocation: queries.byLocation,
byBbox: queries.byBbox,
Expand Down
7 changes: 7 additions & 0 deletions src/resolvers-cassandra/Messages/mutations.js
@@ -1,12 +1,19 @@
'use strict';

const streamingController = require('../../clients/streaming/StreamingController');
const eventHubSender = require('../../clients/eventhub/EventHubSender');
const trackEvent = require('../../clients/appinsights/AppInsightsClient').trackEvent;
const restartPipelineExtraProps = require('../../clients/appinsights/LoggingClient').restartPipelineExtraProps;

function restartPipeline(args, res) { // eslint-disable-line no-unused-vars
return streamingController.restartPipeline();
}

function publishEvents(args, res) { // eslint-disable-line no-unused-vars
return eventHubSender.sendMessages(args && args.input && args.input.messages);
}

module.exports = {
restartPipeline: trackEvent(restartPipeline, 'restartPipeline', restartPipelineExtraProps()),
publishEvents: trackEvent(publishEvents, 'publishEvents')
};
12 changes: 2 additions & 10 deletions src/resolvers-cassandra/Settings/index.js
Expand Up @@ -8,24 +8,16 @@ module.exports = {
removeSite: mutations.removeSite,
editSite: mutations.editSite,
modifyStreams: mutations.modifyStreams,
modifyFacebookPages: mutations.modifyFacebookPages,
removeFacebookPages: mutations.removeFacebookPages,
modifyTrustedTwitterAccounts: mutations.modifyTrustedTwitterAccounts,
removeTrustedTwitterAccounts: mutations.removeTrustedTwitterAccounts,
modifyTwitterAccounts: mutations.modifyTwitterAccounts,
removeTwitterAccounts: mutations.removeTwitterAccounts,
modifyBlacklist: mutations.modifyBlacklist,
removeBlacklist: mutations.removeBlacklist,
removeKeywords: mutations.removeKeywords,
addKeywords: mutations.addKeywords,
addTrustedSources: mutations.addTrustedSources,
removeTrustedSources: mutations.removeTrustedSources,

siteTerms: queries.siteTerms,
sites: queries.sites,
trustedSources: queries.trustedSources,
streams: queries.streams,
twitterAccounts: queries.twitterAccounts,
trustedTwitterAccounts: queries.trustedTwitterAccounts,
facebookPages: queries.facebookPages,
facebookAnalytics: queries.facebookAnalytics,
termBlacklist: queries.termBlacklist
};

0 comments on commit ede14a7

Please sign in to comment.