Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Reporter to output both UA and GA4 data in reports #769

Merged
merged 200 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
200 commits
Select commit Hold shift + click to select a range
cc76386
update readme
Mesele29 Oct 23, 2023
7adf277
start updates with data api
Mesele29 Oct 30, 2023
7ba7b42
updated with ga4 custom api mapping
Mesele29 Nov 1, 2023
58eabdb
update reports with api mapping
Mesele29 Nov 1, 2023
094f98a
merge with develop
Mesele29 Nov 2, 2023
74802fb
log implement
Mesele29 Nov 2, 2023
977c371
merge with develop
Mesele29 Nov 3, 2023
1d080e9
comment out tests
Mesele29 Nov 27, 2023
9b43c97
Merge branch 'develop' of github.com:18F/analytics-reporter into migr…
scottqueen-bixal Dec 7, 2023
2c8b3ed
updated lock file
scottqueen-bixal Dec 7, 2023
39b5177
new nvmrc file to keep node in sync
scottqueen-bixal Dec 8, 2023
5c8270c
update node in docker container
scottqueen-bixal Dec 8, 2023
21391bc
winston yelling at us
scottqueen-bixal Dec 8, 2023
64c7edf
resolve merge
scottqueen-bixal Dec 8, 2023
e34524f
data is now an array
scottqueen-bixal Dec 8, 2023
7ad6364
just build the query in the reports object
scottqueen-bixal Dec 8, 2023
50fae44
update for new object iterative and name mapping
scottqueen-bixal Dec 8, 2023
e7a2b66
update node in compose
scottqueen-bixal Dec 8, 2023
a10d7d0
point at index and ignore synk for now
scottqueen-bixal Dec 8, 2023
dd803d7
no need to use the promise for now, revisit later
scottqueen-bixal Dec 8, 2023
2095310
begining to update the report schema
scottqueen-bixal Dec 8, 2023
0702501
close space
scottqueen-bixal Dec 8, 2023
497d08f
include APC ENV variable in example
scottqueen-bixal Dec 8, 2023
1521523
remove x
scottqueen-bixal Dec 11, 2023
ca9e008
include a sampling report
scottqueen-bixal Dec 11, 2023
61cb1d1
query needs to be rebuilt here again
scottqueen-bixal Dec 11, 2023
87fb391
revert and include a few more items from original query build
scottqueen-bixal Dec 11, 2023
7323c37
pass through the built query rather than get it from data response
scottqueen-bixal Dec 11, 2023
854acc0
hold logs
scottqueen-bixal Dec 11, 2023
600a5fb
update reports
scottqueen-bixal Dec 11, 2023
44c3998
limit 1000k
scottqueen-bixal Dec 11, 2023
ca3a824
more reports
scottqueen-bixal Dec 11, 2023
4055db0
includes updated reports schema except exits
scottqueen-bixal Dec 12, 2023
aac641b
format date
scottqueen-bixal Dec 12, 2023
40936a0
qa pass
scottqueen-bixal Dec 13, 2023
2047754
removing unneeded key mapping, updating needed
scottqueen-bixal Dec 13, 2023
4646dce
update agency env config
scottqueen-bixal Dec 14, 2023
96296ad
update for realtime report query config
scottqueen-bixal Dec 14, 2023
d2b219d
allow default key config for ADC
scottqueen-bixal Dec 14, 2023
16dbffc
update googleapis
scottqueen-bixal Dec 14, 2023
c9c949d
bring back query authorizer
scottqueen-bixal Dec 14, 2023
5f66af5
only check for sampling if it returns
scottqueen-bixal Dec 14, 2023
9817e7e
remove log
scottqueen-bixal Dec 14, 2023
f86cd1a
use fullpageurl
scottqueen-bixal Dec 15, 2023
c3905f2
update name
scottqueen-bixal Dec 15, 2023
8ba1091
update to new data v1 beta api schema for query
scottqueen-bixal Dec 15, 2023
bb4f234
now an array of objects
scottqueen-bixal Dec 15, 2023
51224de
update orderBys
scottqueen-bixal Dec 15, 2023
28250b9
start converting usa reports to GA4 query schema
scottqueen-bixal Dec 15, 2023
3e150bf
introduce version tagging in data
scottqueen-bixal Dec 18, 2023
e5b771e
revert docker updates
scottqueen-bixal Dec 18, 2023
a85bc5e
revert docker updates
scottqueen-bixal Dec 18, 2023
a5c7e69
revert changes to index
scottqueen-bixal Dec 18, 2023
689b1b3
revert package changes
scottqueen-bixal Dec 18, 2023
36eeeba
new migration to create ga4 table
scottqueen-bixal Dec 18, 2023
057368f
replace db value so ga4 data get's written to new table
scottqueen-bixal Dec 18, 2023
0da368d
move to minor version for tagging
scottqueen-bixal Dec 18, 2023
cabcf53
Add pipeline for ga4
Dec 18, 2023
6135f7a
Add pipeline for ga4 2
Dec 18, 2023
9f70af4
update query params to use new Google Data construction
scottqueen-bixal Dec 26, 2023
93e80a3
Merge branch 'migrate-ga3-to-ga4' of github.com:18F/analytics-reporte…
scottqueen-bixal Dec 26, 2023
fd89a48
filters out other, and null
scottqueen-bixal Dec 26, 2023
a5c061b
include map for fileName
scottqueen-bixal Dec 26, 2023
70fd073
remove console log
scottqueen-bixal Dec 26, 2023
8225e5f
include env vars with test config
scottqueen-bixal Dec 26, 2023
f02f61c
update readme to show new report schema
scottqueen-bixal Dec 26, 2023
865dc31
data now comes back at the first index of the array
scottqueen-bixal Dec 26, 2023
c1f05fa
pass db config to test connection
scottqueen-bixal Dec 26, 2023
3b52cde
run tests for all CircleCI builds
ryanwoldatwork Jan 4, 2024
6d2d76b
remove package references from cfignore
ryanwoldatwork Jan 5, 2024
cbc146e
add Procfile
ryanwoldatwork Jan 5, 2024
788a3b0
don't cfignore /node_modules
ryanwoldatwork Jan 5, 2024
8629d5d
trying node 20
ryanwoldatwork Jan 5, 2024
756ae70
load new relic first
ryanwoldatwork Jan 5, 2024
d3cdb09
logger isn't defined yet, so don't log the skipping
ryanwoldatwork Jan 5, 2024
b31fc32
don't exclude package.json
ryanwoldatwork Jan 5, 2024
6c4320f
again, don't log
ryanwoldatwork Jan 5, 2024
8b95997
node deploy/cron.js
ryanwoldatwork Jan 5, 2024
ef1b19f
build before push
ryanwoldatwork Jan 5, 2024
8f06322
npm i for each environment
ryanwoldatwork Jan 5, 2024
bf9d565
updated reports files
scottqueen-bixal Jan 5, 2024
3d5c00a
update devices to 30days range
scottqueen-bixal Jan 5, 2024
55604a3
filter other out of cities report
scottqueen-bixal Jan 5, 2024
d5193a0
don't ignore *.env files
ryanwoldatwork Jan 5, 2024
41cc7e5
update report for today to include sort by hours and exclude empties
scottqueen-bixal Jan 5, 2024
333745d
require ssl
ryanwoldatwork Jan 5, 2024
c5793d8
update npm packages
ryanwoldatwork Jan 5, 2024
8e95782
make restarts more visible in logs
ryanwoldatwork Jan 5, 2024
7d7e5a0
Merge branch 'develop' of github.com:18F/analytics-reporter into migr…
scottqueen-bixal Jan 8, 2024
359c59b
updated lock file
scottqueen-bixal Jan 8, 2024
cb620b7
turn off test(s) temp
scottqueen-bixal Jan 8, 2024
5e27971
disable workflow tmp
scottqueen-bixal Jan 8, 2024
0b4e546
update config with develop_deploy
scottqueen-bixal Jan 8, 2024
a02c7e3
comment out publish crons testing temp
scottqueen-bixal Jan 9, 2024
c456cc2
Merge pull request #732 from 18F/remove-crons-publish-s3
scottqueen-bixal Jan 9, 2024
8347c14
check process rather than default port
scottqueen-bixal Jan 9, 2024
692e385
Add some automation to create the GA4 Credentials file
Jan 9, 2024
fbf4a53
Merge branch 'migrate-ga3-to-ga4' of https://github.com/18F/analytics…
Jan 9, 2024
dbf193f
Merge pull request #733 from 18F/update-deploy-health-check
XavierMetichecchia Jan 9, 2024
7899c2c
Add some automation to create the GA4 Credentials file 2
Jan 9, 2024
fc50b6a
Add some automation to create the GA4 Credentials file 3
Jan 9, 2024
377eaae
revert back to default health check
scottqueen-bixal Jan 10, 2024
16027c8
calculate offset for api_run
scottqueen-bixal Jan 10, 2024
842db80
Merge pull request #734 from 18F/update-deploy-health-check
XavierMetichecchia Jan 10, 2024
8c8b219
uncomment offset function
scottqueen-bixal Jan 10, 2024
c47d656
Merge pull request #735 from 18F/update-deploy-health-check
XavierMetichecchia Jan 10, 2024
050a678
update devices to 90days, indlude startDate yesterday for today
scottqueen-bixal Jan 11, 2024
2d105f6
move api_run interval into calculated daily run offset
scottqueen-bixal Jan 11, 2024
fda4347
filter out (other) in top pages 7 days report
scottqueen-bixal Jan 11, 2024
2a2c622
remove (other) from top-domains-7-days
scottqueen-bixal Jan 11, 2024
bcde8bc
update npm packages
ryanwoldatwork Jan 11, 2024
40d7ffb
add snyk badge, remove gemnasium
ryanwoldatwork Jan 11, 2024
405e714
update npm packages
ryanwoldatwork Jan 11, 2024
610e7b0
move over dimesion order to last-48-hrs report
scottqueen-bixal Jan 12, 2024
e020f67
Merge branch 'develop' of github.com:18F/analytics-reporter into migr…
scottqueen-bixal Jan 12, 2024
4c6ed95
new lock file
scottqueen-bixal Jan 12, 2024
3bcfa25
remove api version config
scottqueen-bixal Jan 12, 2024
b082a03
set version to 2
scottqueen-bixal Jan 12, 2024
07633b7
uncomment code
scottqueen-bixal Jan 12, 2024
53ac0f0
uncomment code
scottqueen-bixal Jan 12, 2024
fc8631b
remove sampling level default
scottqueen-bixal Jan 16, 2024
0a2512a
new sessions report and updated language report
scottqueen-bixal Jan 16, 2024
49f9339
updated lock
scottqueen-bixal Jan 16, 2024
611b831
Merge pull request #750 from 18F/update-lock
scottqueen-bixal Jan 16, 2024
8da80d1
include version 1 UA application with specific env variables
scottqueen-bixal Jan 17, 2024
e471b1b
update google api package
scottqueen-bixal Jan 17, 2024
2112bd9
remove unused package config
scottqueen-bixal Jan 17, 2024
91c6291
destructre data object before processing
scottqueen-bixal Jan 17, 2024
782c36c
no need to use the key file path in the ua app
scottqueen-bixal Jan 17, 2024
3aa8ea6
remove realtime conditional and update promise
scottqueen-bixal Jan 17, 2024
fa55b66
use new Auth object
scottqueen-bixal Jan 17, 2024
8a24756
remove s3
scottqueen-bixal Jan 17, 2024
88ab8f9
remove s3 config
scottqueen-bixal Jan 17, 2024
2146577
not using s3 in ua app
scottqueen-bixal Jan 17, 2024
7af60cc
remove s3
scottqueen-bixal Jan 17, 2024
b2928e8
remove s3 test
scottqueen-bixal Jan 17, 2024
e41f780
no longer publishes
scottqueen-bixal Jan 17, 2024
2030881
turn off cron tasks for now, tmp
scottqueen-bixal Jan 17, 2024
9fc2124
add better descripter to logger info for ua api run
scottqueen-bixal Jan 17, 2024
159f9bd
Merge pull request #754 from 18F/turn-off-crons
scottqueen-bixal Jan 17, 2024
0867ad0
add back all the crons
scottqueen-bixal Jan 17, 2024
b05581b
remove env var
scottqueen-bixal Jan 17, 2024
36799b8
remove env variable from ua
scottqueen-bixal Jan 17, 2024
3f3f188
Merge branch 'develop' of github.com:18F/analytics-reporter into migr…
scottqueen-bixal Jan 19, 2024
7853c15
fix type on interval function call
scottqueen-bixal Jan 19, 2024
2f29ef5
fix type on interval function call
scottqueen-bixal Jan 19, 2024
73bf719
update and remove reports that do not have 1-1 mapping with UA => GA4
scottqueen-bixal Jan 19, 2024
c6dea43
updates language to language code
scottqueen-bixal Jan 19, 2024
4056ef3
update devices to device for consistency
scottqueen-bixal Jan 19, 2024
f8dc3d0
Merge pull request #759 from 18F/audit-reports-api
scottqueen-bixal Jan 22, 2024
83f7670
revert dimension back to language
scottqueen-bixal Jan 23, 2024
58ff0db
calculate languageCode on api reports
scottqueen-bixal Jan 23, 2024
0b0b316
include both language code and language key in s3 language report
scottqueen-bixal Jan 23, 2024
4469a8c
include mapping
scottqueen-bixal Jan 23, 2024
cde46c1
update key
scottqueen-bixal Jan 23, 2024
b88a966
update our example to include key values needed to run both UA and GA…
scottqueen-bixal Jan 26, 2024
e25735e
tab image key over
scottqueen-bixal Jan 26, 2024
d75d583
update to 18 engine
scottqueen-bixal Jan 26, 2024
bd9402a
Add ability to run tests locally with docker
levinmr Jan 25, 2024
77287bb
Fix tests for analytics reporter and fix cut/filter logic
levinmr Jan 26, 2024
3506c5c
Fix result formatter and totaler tests
levinmr Jan 29, 2024
b613251
Fix postgres publisher tests
levinmr Jan 30, 2024
9b47c00
Fix tests for auth and query builder
levinmr Jan 30, 2024
ea5a0c2
Re-enable CI tests
levinmr Jan 30, 2024
863a840
Fix UA tests and add them to mocha config
levinmr Jan 30, 2024
e0e35d6
Merge pull request #767 from 18F/feature/fix_tests
levinmr Jan 30, 2024
27de716
remove commented lines
scottqueen-bixal Jan 30, 2024
c637dbb
updated package
scottqueen-bixal Jan 30, 2024
b133bb8
update to use node 20.10
scottqueen-bixal Jan 30, 2024
5b71410
remove version
scottqueen-bixal Jan 30, 2024
3236c48
drop index
scottqueen-bixal Jan 30, 2024
3a1fcc4
not using version col
scottqueen-bixal Jan 30, 2024
0381e77
migrate date_time to date
scottqueen-bixal Jan 30, 2024
94a6e7a
remove version col
scottqueen-bixal Jan 30, 2024
142adf4
Merge pull request #726 from 18F/migrate-ga3-to-ga4
levinmr Jan 31, 2024
93d1f9d
Add step to develop workflow to write ga4 creds file
Jan 31, 2024
a3d7842
Merge branch 'stage' of github.com:18F/analytics-reporter into develop
scottqueen-bixal Jan 31, 2024
295ec84
destructure google on import
scottqueen-bixal Feb 1, 2024
fe5eb85
update mock structure to match updated client module
scottqueen-bixal Feb 1, 2024
db5a79b
Merge pull request #770 from 18F/fix-ua-client
scottqueen-bixal Feb 1, 2024
e771a5c
Fix paths in UA api.sh script
levinmr Feb 1, 2024
fedf45b
Merge pull request #771 from 18F/bugfix_ua_api_script
XavierMetichecchia Feb 1, 2024
e82f8aa
update logging in cron for better reporting of errors
scottqueen-bixal Feb 2, 2024
9719d5f
remove unused logger
scottqueen-bixal Feb 2, 2024
de22797
revert to use ua root path
scottqueen-bixal Feb 2, 2024
d5d7ec6
dont ignore ua agency env config files
scottqueen-bixal Feb 2, 2024
18b6c21
Merge pull request #774 from 18F/update-ua-api-sh
levinmr Feb 2, 2024
a2a6950
rename education
scottqueen-bixal Feb 2, 2024
fc11da7
Merge pull request #777 from 18F/update-env-file-name
levinmr Feb 2, 2024
7d48d44
Create an application logger
levinmr Feb 2, 2024
fbd7e5c
Merge pull request #773 from 18F/improve-logging
levinmr Feb 2, 2024
6790075
update aws-sdk
scottqueen-bixal Feb 2, 2024
fe10381
update aws-sdk
scottqueen-bixal Feb 2, 2024
aad7701
Convert S3 publish to use AWS SDK v3 style commands
levinmr Feb 2, 2024
013a7b8
Merge pull request #775 from 18F/update-aws-sdk
levinmr Feb 2, 2024
0416d98
Improve logging further
levinmr Feb 5, 2024
35803f4
Add logging to JSON formatter to reveal bug
levinmr Feb 5, 2024
ba1eeb2
Merge pull request #781 from 18F/improve_logging_part_2
levinmr Feb 5, 2024
486bcaa
Handle totals correctly when report data is empty
levinmr Feb 5, 2024
1e93efb
Merge pull request #782 from 18F/bugfix/handle_empty_data_response
levinmr Feb 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
name: run tests
command: npm test


develop_deploy:
docker:
- image: cimg/node:16.19.1
Expand All @@ -50,6 +49,11 @@ jobs:
sudo curl -v -L -o cf8-cli-installer_8.7.4_x86-64.deb 'https://packages.cloudfoundry.org/stable?release=debian64&version=8.7.4'
sudo dpkg -i cf8-cli-installer_8.7.4_x86-64.deb

- run:
name: Write Google GA4 Credentails file from value in CircleCI env var.
command: |
echo $GA4_CREDS > ./my-analytics-ga4-65057af58daa.json

- run:
name: deploy
command: |
Expand Down Expand Up @@ -83,6 +87,11 @@ jobs:
sudo curl -v -L -o cf8-cli-installer_8.7.4_x86-64.deb 'https://packages.cloudfoundry.org/stable?release=debian64&version=8.7.4'
sudo dpkg -i cf8-cli-installer_8.7.4_x86-64.deb

- run:
name: Write Google GA4 Credentails file from value in CircleCI env var.
command: |
echo $GA4_CREDS > ./my-analytics-ga4-65057af58daa.json

- run:
name: deploy
command: |
Expand Down
14 changes: 14 additions & 0 deletions .mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff: true
extension: ['js']
package: './package.json'
slow: '75'
spec:
- 'test/**/*.js'
- 'ua/test/**/*.js'
timeout: '2000'
ui: 'bdd'
watch-files:
- 'src/**/*.js'
- 'test/**/*.js'
- 'ua/src/**/*.js'
- 'ua/test/**/*.js'
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.11
90 changes: 66 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ alias analytics="docker run -t -v ${HOME}:${HOME} -e ANALYTICS_REPORT_EMAIL -e A
To make this command working as expected you should export the env vars as follows:

```bash
export ANALYTICS_REPORT_EMAIL= "your-report-email"
export ANALYTICS_REPORT_EMAIL="your-report-email"
export ANALYTICS_REPORT_IDS="your-report-ids"
export ANALYTICS_KEY="your-key"
```
Expand Down Expand Up @@ -180,47 +180,68 @@ A report might look something like this:
"name": "devices",
"query": {
"dimensions": [
"ga:date",
"ga:deviceCategory"
{
"name": "date"
},
{
"name": "deviceCategory"
}
],
"metrics": [
"ga:sessions"
{
"name": "sessions"
}
],
"start-date": "90daysAgo",
"end-date": "yesterday",
"sort": "ga:date"
"dateRanges": [
{
"startDate": "90daysAgo",
"endDate": "yesterday"
}
],
"orderBys": [
{
"dimension": {
"dimensionName": "date"
},
"desc": true
}
],
"samplingLevel": "HIGHER_PRECISION",
"limit": "10000",
"property": "properties/393249053"
},
"meta": {
"name": "Devices",
"description": "Weekly desktop/mobile/tablet visits by day for all sites."
"description": "90 days of desktop/mobile/tablet visits for all sites."
},
"data": [
{
"date": "2014-10-14",
"device": "desktop",
"visits": "11495462"
"date": "2023-12-25",
"device": "mobile",
"visits": "13681896"
},
{
"date": "2014-10-14",
"device": "mobile",
"visits": "2499586"
"date": "2023-12-25",
"device": "desktop",
"visits": "5775002"
},
{
"date": "2014-10-14",
"date": "2023-12-25",
"device": "tablet",
"visits": "976396"
"visits": "367039"
},
// ...
...
],
"totals": {
"visits": 3584551745,
"devices": {
"mobile": 213920363,
"desktop": 755511646,
"tablet": 81874189
},
"start_date": "2014-10-14",
"end_date": "2015-01-11"
}
"mobile": 2012722956,
"desktop": 1513968883,
"tablet": 52313579,
"smart tv": 5546327
}
},
"taken_at": "2023-12-26T20:52:50.062Z"
}
```

Expand Down Expand Up @@ -344,6 +365,27 @@ Compose:
docker-compose up
```

#### Running unit tests locally

The unit tests require a postgres database to be running and accepting
connections at 127.0.0.1:5432

To run the test database locally with docker:

```shell
docker-compose -f docker-compose.test.yml up
```

The test scripts run database migrations and then the tests themselves. These
require database connection details to be provided in the shell environment:

```shell
POSTGRES_PASSWORD=123abc \
POSTGRES_USER=analytics \
POSTGRES_DATABASE=analytics_reporter_test \
npm test
```

### Public domain

This project is in the worldwide [public domain](LICENSE.md). As stated in [CONTRIBUTING](CONTRIBUTING.md):
Expand Down
162 changes: 74 additions & 88 deletions deploy/cron.js
Original file line number Diff line number Diff line change
@@ -1,116 +1,102 @@
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config()
if (process.env.NODE_ENV !== "production") {
require("dotenv").config();
}

if (process.env.NEW_RELIC_APP_NAME) {
require("newrelic")
require("newrelic");
}

const spawn = require("child_process").spawn;
const winston = require("winston")

const logger = winston.createLogger({
level: 'debug',
format: winston.format.json(),
transports: [new winston.transports.Console({level: 'debug'})],
});
const logger = require('../src/logger').initialize();

logger.info("===================================");
logger.info("=== STARTING ANALYTICS-REPORTER ===");
logger.info(" Running /deploy/cron.js");
logger.info("===================================");

const scriptRootPath = `${process.env.ANALYTICS_ROOT_PATH}/deploy`

var api_run = function() {
logger.info("about to run api.sh");

var api = spawn(`${scriptRootPath}/api.sh`)
api.stdout.on("data", (data) => {
logger.info("[api.sh]", data.toString().trim())
})
api.stderr.on("data", (data) => {
logger.info("[api.sh]", data.toString().trim())
})
api.on("exit", (code) => {
logger.info("api.sh exitted with code:", code)
})
}
const scriptRootPath = `${process.env.ANALYTICS_ROOT_PATH}/deploy`;
const scriptUARootPath = `${process.env.ANALYTICS_UA_ROOT_PATH}/deploy`;

var daily_run = function() {
logger.info("about to run daily.sh");

var daily = spawn(`${scriptRootPath}/daily.sh`)
daily.stdout.on("data", (data) => {
logger.info("[daily.sh]", data.toString().trim())
})
daily.stderr.on("data", (data) => {
logger.info("[daily.sh]", data.toString().trim())
})
daily.on("exit", (code) => {
logger.info("daily.sh exitted with code:", code)
})
}
const runScriptWithLogName = (scriptPath, scriptLoggingName) => {
logger.info(`Beginning: ${scriptLoggingName}`);
logger.info(`File path: ${scriptPath}`);
const childProcess = spawn(scriptPath);

var hourly_run = function(){
logger.info("about to run hourly.sh");

var hourly = spawn(`${scriptRootPath}/hourly.sh`)
hourly.stdout.on("data", (data) => {
logger.info("[hourly.sh]", data.toString().trim())
})
hourly.stderr.on("data", (data) => {
logger.info("[hourly.sh]", data.toString().trim())
})
hourly.on("exit", (code) => {
logger.info("hourly.sh exitted with code:", code)
})
}
childProcess.stdout.on("data", (data) => {
logger.info(`[${scriptLoggingName}]`);
// Writes logging output from child processes to console.
console.log(data.toString().trim())
});

var realtime_run = function(){
logger.info("about to run realtime.sh");

var realtime = spawn(`${scriptRootPath}/realtime.sh`)
realtime.stdout.on("data", (data) => {
logger.info("[realtime.sh]", data.toString().trim())
})
realtime.stderr.on("data", (data) => {
logger.info("[realtime.sh]", data.toString().trim())
})
realtime.on("exit", (code) => {
logger.info("realtime.sh exitted with code:", code)
})
childProcess.stderr.on("data", (data) => {
logger.error(`[${scriptLoggingName}]`);
// Writes error logging output from child processes to console.
console.log(data.toString().trim())
});

childProcess.on("exit", (code) => {
logger.info(`${scriptLoggingName} exitted with code: ${code}`);
});
}

const api_ua_run = () => {
runScriptWithLogName(`${scriptUARootPath}/api.sh`, 'ua - api.sh')
};

const api_run = () => {
runScriptWithLogName(`${scriptRootPath}/api.sh`, 'api.sh')
};

const daily_run = () => {
runScriptWithLogName(`${scriptRootPath}/daily.sh`, 'daily.sh')
};

const hourly_run = () => {
runScriptWithLogName(`${scriptRootPath}/hourly.sh`, 'hourly.sh')
};

const realtime_run = () => {
runScriptWithLogName(`${scriptRootPath}/realtime.sh`, 'realtime.sh')
};

/**
Daily reports run every morning at 10 AM UTC.
This calculates the offset between now and then for the next scheduled run.
Daily reports run every morning at 10 AM UTC.
This calculates the offset between now and then for the next scheduled run.
*/
var calculateNextDailyRunTimeOffset = function(){
const currentTime = new Date();
const nextRunTime = new Date(
currentTime.getFullYear(),
currentTime.getMonth(),
currentTime.getDate() + 1,
10 - currentTime.getTimezoneOffset() / 60
);
return (nextRunTime - currentTime) % (1000 * 60 * 60 * 24)
}
const calculateNextDailyRunTimeOffset = () => {
const currentTime = new Date();
const nextRunTime = new Date(
currentTime.getFullYear(),
currentTime.getMonth(),
currentTime.getDate() + 1,
10 - currentTime.getTimezoneOffset() / 60
);
return (nextRunTime - currentTime) % (1000 * 60 * 60 * 24);
};

logger.info("starting cron.js!");
/**
* All scripts run immediately upon application start, then run again at
* intervals going forward.
*/
api_run();
api_ua_run();
daily_run();
hourly_run();
realtime_run();
//api
setInterval(api_run,1000 * 60 * 60 * 24)
//daily

// daily
setTimeout(() => {
// Run at 10 AM UTC, then every 24 hours afterwards
daily_run();
setInterval(daily_run, 1000 * 60 * 60 * 24);
// Run at 10 AM UTC, then every 24 hours afterwards
daily_run();
setInterval(daily_run, 1000 * 60 * 60 * 24);
//api
api_run();
setInterval(api_run, 1000 * 60 * 60 * 24);
//ua api
api_ua_run();
setInterval(api_ua_run, 1000 * 60 * 60 * 24);
}, calculateNextDailyRunTimeOffset());
//hourly
setInterval(hourly_run,1000 * 60 * 60);
setInterval(hourly_run, 1000 * 60 * 60);
//realtime
setInterval(realtime_run,1000 * 60 * 5);
setInterval(realtime_run, 1000 * 60 * 5);
3 changes: 2 additions & 1 deletion deploy/envs/agency-international-development.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Agency for International Development
export ANALYTICS_REPORT_IDS="ga:68380943"
# USAID Agency
export ANALYTICS_REPORT_IDS="395450427"
export AGENCY_NAME=agency-international-development
export AWS_BUCKET_PATH=data/agency-international-development
3 changes: 2 additions & 1 deletion deploy/envs/agriculture.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Department of Agriculture
export ANALYTICS_REPORT_IDS="ga:65240995"
# USDA Agency
export ANALYTICS_REPORT_IDS="395461442"
export AGENCY_NAME=agriculture
export AWS_BUCKET_PATH=data/agriculture

3 changes: 2 additions & 1 deletion deploy/envs/commerce.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Department of Commerce
export ANALYTICS_REPORT_IDS="ga:66877186"
# DOC Agency
export ANALYTICS_REPORT_IDS="395253935"
export AGENCY_NAME=commerce
export AWS_BUCKET_PATH=data/commerce
3 changes: 2 additions & 1 deletion deploy/envs/defense.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Department of Defense
export ANALYTICS_REPORT_IDS="ga:67120289"
# DOD Agency
export ANALYTICS_REPORT_IDS="395251747"
export AGENCY_NAME=defense
export AWS_BUCKET_PATH=data/defense
Loading