-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #939 from 18F/feature/replace_cron_script_with_sch…
…eduler [Tech Debt] Job scheduling with the Bree library
- Loading branch information
Showing
13 changed files
with
430 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
if (process.env.NODE_ENV !== "production") { | ||
require("dotenv").config(); | ||
} | ||
|
||
if (process.env.NEW_RELIC_APP_NAME) { | ||
require("newrelic"); | ||
} | ||
|
||
const logger = require("../src/logger").initialize(); | ||
logger.info("==================================="); | ||
logger.info("=== STARTING ANALYTICS-REPORTER ==="); | ||
logger.info(" Running /deploy/publisher.js"); | ||
logger.info("==================================="); | ||
|
||
// Job Scheduler | ||
const Bree = require("bree"); | ||
const bree = new Bree({ | ||
logger, | ||
jobs: [ | ||
// Runs `../jobs/realtime.js` 1 millisecond after the process starts and | ||
// then every 15 minutes going forward. | ||
{ | ||
name: "realtime", | ||
timeout: "1", | ||
interval: "15m", | ||
}, | ||
// Runs `../jobs/daily.js` 1 minute after the process starts and then at | ||
// 10:01 AM every day going forward. | ||
{ | ||
name: "daily", | ||
timeout: "1m", | ||
interval: "at 10:01 am", | ||
}, | ||
// Runs `../jobs/api.js` 2 minutes after the process starts and then at | ||
// 10:02 AM every day going forward. | ||
{ | ||
name: "api", | ||
timeout: "2m", | ||
interval: "at 10:02 am", | ||
}, | ||
], | ||
}); | ||
|
||
(async () => { | ||
await bree.start(); | ||
})(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
process.env.ANALYTICS_REPORTS_PATH = "reports/api.json"; | ||
process.env.ANALYTICS_SCRIPT_NAME = "api.js"; | ||
|
||
const { runQueuePublish } = require("../index.js"); | ||
const options = { | ||
frequency: "daily", | ||
debug: true, | ||
"write-to-database": true, | ||
agenciesFile: `${process.env.ANALYTICS_ROOT_PATH}/deploy/agencies.json`, | ||
}; | ||
const logger = require("../src/logger.js").initialize(); | ||
|
||
(async () => { | ||
logger.info(`Beginning job: ${process.env.ANALYTICS_SCRIPT_NAME}`); | ||
|
||
try { | ||
await runQueuePublish(options); | ||
logger.info(`Job completed: ${process.env.ANALYTICS_SCRIPT_NAME}`); | ||
} catch (e) { | ||
logger.error(`Job exited with error: ${process.env.ANALYTICS_SCRIPT_NAME}`); | ||
logger.error(e); | ||
throw e; | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
process.env.ANALYTICS_REPORTS_PATH = "reports/usa.json"; | ||
process.env.ANALYTICS_SCRIPT_NAME = "daily.js"; | ||
|
||
const { runQueuePublish } = require("../index.js"); | ||
const options = { | ||
publish: true, | ||
frequency: "daily", | ||
slim: true, | ||
debug: true, | ||
csv: true, | ||
json: true, | ||
agenciesFile: `${process.env.ANALYTICS_ROOT_PATH}/deploy/agencies.json`, | ||
}; | ||
const logger = require("../src/logger.js").initialize(); | ||
|
||
(async () => { | ||
logger.info(`Beginning job: ${process.env.ANALYTICS_SCRIPT_NAME}`); | ||
|
||
try { | ||
await runQueuePublish(options); | ||
logger.info(`Job completed: ${process.env.ANALYTICS_SCRIPT_NAME}`); | ||
} catch (e) { | ||
logger.error(`Job exited with error: ${process.env.ANALYTICS_SCRIPT_NAME}`); | ||
logger.error(e); | ||
throw e; | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
process.env.ANALYTICS_REPORTS_PATH = "reports/usa.json"; | ||
process.env.ANALYTICS_SCRIPT_NAME = "realtime.js"; | ||
|
||
const { runQueuePublish } = require("../index.js"); | ||
const options = { | ||
publish: true, | ||
frequency: "realtime", | ||
slim: true, | ||
debug: true, | ||
csv: true, | ||
json: true, | ||
agenciesFile: `${process.env.ANALYTICS_ROOT_PATH}/deploy/agencies.json`, | ||
}; | ||
const logger = require("../src/logger.js").initialize(); | ||
|
||
(async () => { | ||
logger.info(`Beginning job: ${process.env.ANALYTICS_SCRIPT_NAME}`); | ||
|
||
try { | ||
await runQueuePublish(options); | ||
logger.info(`Job completed: ${process.env.ANALYTICS_SCRIPT_NAME}`); | ||
} catch (e) { | ||
logger.error(`Job exited with error: ${process.env.ANALYTICS_SCRIPT_NAME}`); | ||
logger.error(e); | ||
throw e; | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.