-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
13 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,14 @@ import { parse } from "https://deno.land/[email protected]/flags/mod.ts"; | |
import { Options, wakeDyno } from "./mod.ts"; | ||
|
||
if (import.meta.main) { | ||
console.log('Args', parse(Deno.args)); | ||
const args = parse(Deno.args); | ||
|
||
if (args._.length > 0) { | ||
if (Deno.args.length > 0) { | ||
const args = parse(Deno.args); | ||
const options: Options = { | ||
interval: args.interval ?? 29, | ||
...(args.stopStart && args.stopEnd) && { | ||
...(args.stopStart || args.stopEnd) && { | ||
stopTimes: { | ||
start: args.start, | ||
end: args.end | ||
start: args.stopStart, | ||
end: args.stopEnd | ||
} | ||
} | ||
} | ||
|
@@ -26,6 +24,6 @@ if (import.meta.main) { | |
wakeDyno(urls, options); | ||
} | ||
} else { | ||
console.log('Usage:\n$ heroku-awakener --url <url> --interval <interval> --stopStart <start> --stopEnd <end>') | ||
console.log('Usage:\n$ heroku-awakener --url <url> --interval <interval> --stopStart <start> --stopEnd <end>\n$ heroku-awakener --urls <urls> --interval <interval> --stopStart <start> --stopEnd <end>') | ||
} | ||
} |
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 |
---|---|---|
@@ -1,14 +1,11 @@ | ||
import * as logger from "https://deno.land/[email protected]/log/mod.ts"; | ||
import dayjs from "https://cdn.skypack.dev/[email protected]"; | ||
import isBetween from "https://cdn.skypack.dev/[email protected]/plugin/isBetween.js"; | ||
import customParseFormat from "https://cdn.skypack.dev/[email protected]/plugin/customParseFormat.js"; | ||
|
||
dayjs.extend(customParseFormat); | ||
dayjs.extend(isBetween); | ||
|
||
export function mode() { | ||
return 0; | ||
} | ||
|
||
interface StopTimes { | ||
start: string; | ||
end: string; | ||
|
@@ -23,9 +20,8 @@ function isStopTime(stopTimes: StopTimes): boolean { | |
const { start, end } = stopTimes; | ||
const format = 'HH:mm'; | ||
|
||
// Check if a start and end time are supplied. | ||
if (!start || !end) { | ||
console.log('WARNING: Both a start/end stop time must be defined.'); | ||
logger.warning('Both a start/end stop time must be defined.'); | ||
return true; | ||
} | ||
|
||
|
@@ -50,8 +46,8 @@ export function wakeDyno(url: string, options: Options = {}) { | |
wakeDyno(url, options); | ||
} else { | ||
fetch(url) | ||
.then(() => logging && console.log('Successfully woke the dyno')) | ||
.catch(() => logging && console.log('Error attempting to wake the dyno')) | ||
.then(() => logging && logger.info('Successfully woke the dyno')) | ||
.catch((error: Error) => logging && logger.error(`Attempting to wake the dyno : ${error.message}`)) | ||
.finally(() => wakeDyno(url, options)); | ||
} | ||
}, milliseconds); | ||
|
@@ -68,12 +64,12 @@ export function wakeDynos(urls: string[], options: Options) { | |
|
||
setTimeout(() => { | ||
if (stopTimes && isStopTime(stopTimes)) { | ||
wakeDynos(urls, options); // Recursively call function until not a stop time. | ||
wakeDynos(urls, options); | ||
} else { | ||
const promises = urls.map((url) => fetch(url)); | ||
Promise.all(promises) | ||
.then(() => logging && console.log('Successfully woke all dynos')) | ||
.catch(() => logging && console.log('Error attempting to wake the dynos')) | ||
.then(() => logging && logger.info('Successfully woke all dynos')) | ||
.catch((error: Error) => logging && logger.error(`Attempting to wake the dyno : ${error.message}`)) | ||
.finally(() => wakeDynos(urls, options)); | ||
} | ||
}, milliseconds); | ||
|