Skip to content

Commit

Permalink
Add more detailed logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshopkins committed Jan 29, 2017
1 parent db2378d commit 88133d2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 15 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"babel-plugin-transform-async-to-generator": "^6.16.0",
"babel-plugin-transform-runtime": "^6.15.0",
"debug": "^2.6.0",
"fluture": "^4.3.0",
"isomorphic-fetch": "^2.2.1",
"ramda": "^0.23.0",
Expand Down
10 changes: 7 additions & 3 deletions src/polling/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Future, { after, of } from 'fluture';
import {
always,
chain,
compose,
lensIndex,
Expand All @@ -13,6 +14,7 @@ import {
} from 'ramda';
import { Nothing } from 'sanctuary';

import { log, logC } from '../reporter';
import { getJson, makeRequest } from '../utils';

const handleResponse = chain(res => {
Expand All @@ -24,6 +26,8 @@ const handleResponse = chain(res => {

const poll = compose(handleResponse, makeRequest());

const logInitialPollAttempt = logC(always('Determining if result is complete'));

export const resolvePollRes = (
rej,
res,
Expand All @@ -33,10 +37,10 @@ export const resolvePollRes = (
timeout = setTimeout
) => {
if (propEq('Status', 'UpdatesComplete', data)) {
console.log('Query result complete');
log('Result complete');
res(data);
} else {
console.log('Query result incomplete. Retrying...');
log('Result incomplete. Retrying...');
timeout(() => fetchData(url)(rej, res), 1000);
}
};
Expand All @@ -46,4 +50,4 @@ export const fetchData = (url, pollEndpoint = poll, pollRes = resolvePollRes) =>
pollEndpoint(url).fork(rej, partial(pollRes, [rej, res, fetchData, url]));
};

export default chain(compose(Future, fetchData));
export default chain(compose(Future, fetchData, logInitialPollAttempt));
6 changes: 6 additions & 0 deletions src/reporter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import debug from 'debug';
import { compose, tap } from 'ramda';

export const log = debug('skyscanner-liveflights-api');

export const logC = cb => tap(compose(log, cb));
19 changes: 13 additions & 6 deletions src/session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ import {
import { stringify as formatQuerystring } from 'querystring';
import { format as formatUrl, parse as parseUrl } from 'url';

import { authenticateUrl, log, makeRequest, makeUrl } from '../utils';
import { logC } from '../reporter';
import { authenticateUrl, makeRequest, makeUrl } from '../utils';

const logSession = log(always('Session now accessible \n'));
const logSession = map(logC(always('Session now accessible')));

const logDelay = log(
always(
`Temporarily witholding session access to due to https://support.business.skyscanner.net/hc/en-us/articles/211308489-Flights-Live-Pricing?_ga=1.109063173.1468313731.1483528061#poll \n`
const logDelay = map(
logC(
always(
`Temporarily witholding session access to due to https://support.business.skyscanner.net/hc/en-us/articles/211308489-Flights-Live-Pricing?_ga=1.109063173.1468313731.1483528061#poll`
)
)
);

Expand Down Expand Up @@ -58,7 +61,11 @@ export const createRequestConfig = query => {
);
};

const requestSession = compose(makeRequest, createRequestConfig);
const requestSession = compose(
makeRequest,
logC(always('Creating session')),
createRequestConfig
);

export default query =>
compose(delayResponse, getPollLocation, requestSession(query), makeUrl)();
4 changes: 1 addition & 3 deletions src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Future, { fold, fromPromise } from 'fluture';
import isomorphicFetch from 'isomorphic-fetch';
import { chain, compose, lensProp, map, merge, over, set, tap } from 'ramda';
import { chain, compose, lensProp, merge, over, set } from 'ramda';
import { format as formatUrl } from 'url';

import ApiError from '../error';
Expand All @@ -13,8 +13,6 @@ const addPath = path =>

export const authenticateUrl = urlAuthentication(process.env.API_KEY);

export const log = cb => map(tap(compose(console.log, cb)));

export const makeUrl = path =>
compose(formatUrl, authenticateUrl, addPath(path))({
protocol: 'http',
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,11 @@ babel-types@^6.16.0, babel-types@^6.18.0, babel-types@^6.20.0, babel-types@^6.21
lodash "^4.2.0"
to-fast-properties "^1.0.1"

babylon@6.15.0:
babylon@6.15.0, babylon@^6.13.0:
version "6.15.0"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.15.0.tgz#ba65cfa1a80e1759b0e89fb562e27dccae70348e"

babylon@^6.11.0, babylon@^6.13.0:
babylon@^6.11.0:
version "6.14.1"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.14.1.tgz#956275fab72753ad9b3435d7afe58f8bf0a29815"

Expand Down Expand Up @@ -561,7 +561,7 @@ debug@2.2.0, debug@~2.2.0:
dependencies:
ms "0.7.1"

debug@^2.1.1, debug@^2.2.0:
debug@^2.1.1, debug@^2.2.0, debug@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.0.tgz#bc596bcabe7617f11d9fa15361eded5608b8499b"
dependencies:
Expand Down

0 comments on commit 88133d2

Please sign in to comment.