Skip to content

Commit

Permalink
fix: export GoogleAnalyticsJobs and small fixes (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
dianadevargas committed Dec 12, 2018
1 parent dfcd5ba commit 954ad27
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"config": "1.25.1",
"csvjson": "^4.3.3",
"csvtojson": "^1.1.7",
"googleapis": "^20.1.0",
"inceptum": "^0.9.6",
"lodash": "^4.17.4",
"moment": "^2.18.1",
Expand Down
5 changes: 5 additions & 0 deletions src/destinations/MySqlInsert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ export class MySqlInsert extends EtlDestination {
log.debug(`Delete all records from table : ${this.tableName}`);
await transaction.query(`delete from ${this.tableName}`);
}
// If is an empty batch do not process
if (!fieldList || fieldList.length === 0) {
log.error(`Process empty batch`);
return;
}
return await this.processRecordInTransaction(fieldList, transaction);
});
}
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ export { MySQLDataByKey } from './sources/MySQLDataByKey';
export { StaticSavepointManager } from './savepoints/StaticSavepointManager';
export { MySqlInsert } from './destinations/MySqlInsert';
export { GoogleAnalyticsReporting } from './sources/GoogleAnalyticsReporting';
export { GoogleAnalyticsJobs } from './sources/GoogleAnalyticsJobs';
10 changes: 8 additions & 2 deletions src/sources/MySQLDataByKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,15 @@ export class MySQLDataByKey extends EtlSource {
currentDate: moment().toISOString(),
};
await this.getMaxAndMinIds();
const totalRecords = this.maxId - this.minId + 1;
const totalFound = await this.getTotalRecords();
const totalRecords = totalFound ? this.maxId - this.minId + 1 : 0;
this.totalBatches = (this.currentSavePoint['batchSize'] > 0) ? Math.ceil(totalRecords / this.currentSavePoint['batchSize']) : 0;
this.currentSavePoint['totalBatches'] = this.totalBatches;

// Debug info
log.debug(`Current date: ${this.currentSavePoint['currentDate']}`);
log.debug(`Getting table ${this.tableName}: ids from ${this.minId} to ${this.maxId}. between ${this.currentSavePoint['columnStartValue']} and ${this.currentSavePoint['columnEndValue']} `);
log.debug(`Total records: ${totalRecords} batches: ${this.totalBatches} found: ${totalFound}`);
}

protected async getTotalRecords(): Promise<any> {
Expand Down Expand Up @@ -182,7 +188,7 @@ export class MySQLDataByKey extends EtlSource {

public hasNextBatch(): boolean {
const nextSavePoint = this.getNextSavePoint();
return (nextSavePoint['currentBatch'] <= nextSavePoint['totalBatches']);
return nextSavePoint['totalBatches'] && (nextSavePoint['currentBatch'] <= nextSavePoint['totalBatches']);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/SplitAdwordsCampaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class SplitAdwordsCampaign extends EtlTransformer {
newRecord['location_type'] = locationType;
newRecord['adgroup_match'] = adgroupMatch ;
newRecord['keyword_match'] = keywordHasPlus ? 'BMM' : (newRecord.hasOwnProperty('match_type') ? newRecord['match_type'] : '');
newRecord['postcode'] = ((postcode.length > 0) && Number.isInteger(Number.parseInt(postcode))) ? Number.parseInt(postcode) : '';
newRecord['postcode'] = ((postcode.length > 0) && Number.isInteger(Number.parseInt(postcode, 10))) ? Number.parseInt(postcode, 10) : '';
}

if (newRecord['report_cost']) {
Expand Down
2 changes: 1 addition & 1 deletion src/util/GoogleAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class GoogleAnalytics {
.metric(params.metrics)
.dateRanges(params.dateRanges.startDate, params.dateRanges.endDate)
.filtersExpression(params.filters)
.pageToken(Number.parseInt(params.nextPageToken || this.nextPageToken))
.pageToken(Number.parseInt(params.nextPageToken || this.nextPageToken, 10))
.pageSize(params.maxResults)
.includeEmptyRows(params.includeEmptyRows || true)
.orderBys(params.orderBys || '', 'ASCENDING')
Expand Down

0 comments on commit 954ad27

Please sign in to comment.