-
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.
Merge pull request #310 from TWilkin/294.persistence-indexes
- Loading branch information
Showing
35 changed files
with
1,020 additions
and
631 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 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 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 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,4 @@ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
}; |
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 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,36 @@ | ||
#!/bin/sh | ||
|
||
# the number of seconds the health check file can be since last modification without being unhealthy | ||
AGE=$1 | ||
|
||
# the path to the health check file | ||
HEALTH_FILE=$2 | ||
|
||
if [ -z $AGE ] | ||
then | ||
AGE=12 | ||
fi | ||
|
||
if [ -z $HEALTH_FILE ] | ||
then | ||
HEALTH_FILE=/home/node/app/powerpi_health | ||
fi | ||
|
||
if [ ! -f $HEALTH_FILE ] | ||
then | ||
# the file doesn't exist, that's unhealthy | ||
exit 1 | ||
fi | ||
|
||
NOW=$(date +%s) | ||
HEALTH=$(stat $HEALTH_FILE -c %Y) | ||
SINCE=$(expr $NOW - $HEALTH) | ||
|
||
if [ $SINCE -gt $AGE ] | ||
then | ||
# the health file is older than AGE, that's unhealthy | ||
exit 2 | ||
fi | ||
|
||
# it's newer than AGE, that's healthy | ||
exit 0 |
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,20 @@ | ||
import { open, readFile, utimes } from "fs/promises"; | ||
import { Service } from "typedi"; | ||
|
||
@Service() | ||
export default class FileService { | ||
public async read(path: string) { | ||
return await readFile(path); | ||
} | ||
|
||
public async touch(path: string) { | ||
const now = new Date(); | ||
|
||
try { | ||
await utimes(path, now, now); | ||
} catch (e) { | ||
const handle = await open(path, "a"); | ||
await handle.close(); | ||
} | ||
} | ||
} |
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 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 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,29 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
import { FileService } from "../../src"; | ||
|
||
describe("FileService", () => { | ||
let subject: FileService; | ||
|
||
beforeEach(() => (subject = new FileService())); | ||
|
||
test("read", async () => { | ||
const result = await subject.read(__filename); | ||
|
||
expect(result).toBeDefined(); | ||
|
||
const str = new TextDecoder().decode(result); | ||
expect(str).toContain('test("read",'); | ||
}); | ||
|
||
test("touch", async () => { | ||
const tmpDir = fs.mkdtempSync(__filename); | ||
const file = path.join(tmpDir, "touchy"); | ||
|
||
expect(fs.existsSync(file)).toBeFalsy(); | ||
|
||
await subject.touch(file); | ||
|
||
expect(fs.existsSync(file)).toBeTruthy(); | ||
}); | ||
}); |
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 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 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 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 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 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 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 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.