Skip to content

Commit

Permalink
Merge branch 'main' of github.com:koush/scrypted
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed May 4, 2024
2 parents 9d03566 + 9c9e290 commit 69a3e11
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 39 deletions.
22 changes: 8 additions & 14 deletions .github/workflows/docker-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ jobs:
build:
name: Push Docker image to Docker Hub
runs-on: self-hosted
env:
NODE_VERSION: '20'
strategy:
matrix:
NODE_VERSION: [
# "18",
"20"
]
BASE: ["jammy"]
FLAVOR: ["full", "lite"]
steps:
Expand Down Expand Up @@ -53,15 +51,15 @@ jobs:
uses: docker/build-push-action@v4
with:
build-args: |
NODE_VERSION=${{ matrix.NODE_VERSION }}
NODE_VERSION=${{ env.NODE_VERSION }}
BASE=${{ matrix.BASE }}
context: install/docker/
file: install/docker/Dockerfile.${{ matrix.FLAVOR }}
platforms: linux/amd64,linux/arm64
push: true
tags: |
koush/scrypted-common:${{ matrix.NODE_VERSION }}-${{ matrix.BASE }}-${{ matrix.FLAVOR }}
ghcr.io/koush/scrypted-common:${{ matrix.NODE_VERSION }}-${{ matrix.BASE }}-${{ matrix.FLAVOR }}
koush/scrypted-common:${{ matrix.BASE }}-${{ matrix.FLAVOR }}
ghcr.io/koush/scrypted-common:${{ matrix.BASE }}-${{ matrix.FLAVOR }}
cache-from: type=gha
cache-to: type=gha,mode=max

Expand All @@ -71,10 +69,6 @@ jobs:
runs-on: self-hosted
strategy:
matrix:
NODE_VERSION: [
# "18",
"20"
]
BASE: ["jammy"]
steps:
- name: Check out the repo
Expand Down Expand Up @@ -114,13 +108,13 @@ jobs:
uses: docker/build-push-action@v4
with:
build-args: |
BASE=ghcr.io/koush/scrypted-common:${{ matrix.NODE_VERSION }}-${{ matrix.BASE }}-full
BASE=ghcr.io/koush/scrypted-common:${{ matrix.BASE }}-full
context: install/docker/
file: install/docker/Dockerfile.nvidia
platforms: linux/amd64,linux/arm64
push: true
tags: |
koush/scrypted-common:${{ matrix.NODE_VERSION }}-${{ matrix.BASE }}-nvidia
ghcr.io/koush/scrypted-common:${{ matrix.NODE_VERSION }}-${{ matrix.BASE }}-nvidia
koush/scrypted-common:${{ matrix.BASE }}-nvidia
ghcr.io/koush/scrypted-common:${{ matrix.BASE }}-nvidia
cache-from: type=gha
cache-to: type=gha,mode=max
26 changes: 13 additions & 13 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
strategy:
matrix:
BASE: [
["20-jammy-nvidia", ".s6"],
["20-jammy-full", ".s6"],
["20-jammy-lite", ""],
["jammy-nvidia", ".s6"],
["jammy-full", ".s6"],
["jammy-lite", ""],
]
steps:
- name: Check out the repo
Expand Down Expand Up @@ -80,16 +80,16 @@ jobs:
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ format('koush/scrypted:{0}-v{1}', matrix.BASE, github.event.inputs.publish_tag || steps.package-version.outputs.NPM_VERSION) }}
${{ matrix.BASE[0] == '20-jammy-full' && format('koush/scrypted:{0}', github.event.inputs.tag) || '' }}
${{ github.event.inputs.tag == 'latest' && matrix.BASE[0] == '20-jammy-nvidia' && 'koush/scrypted:nvidia' || '' }}
${{ github.event.inputs.tag == 'latest' && matrix.BASE[0] == '20-jammy-full' && 'koush/scrypted:full' || '' }}
${{ github.event.inputs.tag == 'latest' && matrix.BASE[0] == '20-jammy-lite' && 'koush/scrypted:lite' || '' }}
${{ format('koush/scrypted:v{1}-{0}', matrix.BASE[0], github.event.inputs.publish_tag || steps.package-version.outputs.NPM_VERSION) }}
${{ matrix.BASE[0] == 'jammy-full' && format('koush/scrypted:{0}', github.event.inputs.tag) || '' }}
${{ github.event.inputs.tag == 'latest' && matrix.BASE[0] == 'jammy-nvidia' && 'koush/scrypted:nvidia' || '' }}
${{ github.event.inputs.tag == 'latest' && matrix.BASE[0] == 'jammy-full' && 'koush/scrypted:full' || '' }}
${{ github.event.inputs.tag == 'latest' && matrix.BASE[0] == 'jammy-lite' && 'koush/scrypted:lite' || '' }}
${{ format('ghcr.io/koush/scrypted:{0}-v{1}', matrix.BASE, github.event.inputs.publish_tag || steps.package-version.outputs.NPM_VERSION) }}
${{ matrix.BASE[0] == '20-jammy-full' && format('ghcr.io/koush/scrypted:{0}', github.event.inputs.tag) || '' }}
${{ github.event.inputs.tag == 'latest' && matrix.BASE[0] == '20-jammy-nvidia' && 'ghcr.io/koush/scrypted:nvidia' || '' }}
${{ github.event.inputs.tag == 'latest' && matrix.BASE[0] == '20-jammy-full' && 'ghcr.io/koush/scrypted:full' || '' }}
${{ github.event.inputs.tag == 'latest' && matrix.BASE[0] == '20-jammy-lite' && 'ghcr.io/koush/scrypted:lite' || '' }}
${{ format('ghcr.io/koush/scrypted:v{1}-{0}', matrix.BASE[0], github.event.inputs.publish_tag || steps.package-version.outputs.NPM_VERSION) }}
${{ matrix.BASE[0] == 'jammy-full' && format('ghcr.io/koush/scrypted:{0}', github.event.inputs.tag) || '' }}
${{ github.event.inputs.tag == 'latest' && matrix.BASE[0] == 'jammy-nvidia' && 'ghcr.io/koush/scrypted:nvidia' || '' }}
${{ github.event.inputs.tag == 'latest' && matrix.BASE[0] == 'jammy-full' && 'ghcr.io/koush/scrypted:full' || '' }}
${{ github.event.inputs.tag == 'latest' && matrix.BASE[0] == 'jammy-lite' && 'ghcr.io/koush/scrypted:lite' || '' }}
cache-from: type=gha
cache-to: type=gha,mode=max
1 change: 0 additions & 1 deletion install/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ url: "https://github.com/koush/scrypted"
arch:
- amd64
- aarch64
- armv7
init: false
ingress: true
ingress_port: 11080
Expand Down
2 changes: 1 addition & 1 deletion sdk/types/scrypted_python/scrypted_sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ class ObjectDetectionModel(TypedDict):

class ObjectDetectionSession(TypedDict):

batch: float
batch: float # Denotes that this is the first sample in a batch of samples.
settings: Any
sourceId: str
zones: list[ObjectDetectionZone]
Expand Down
4 changes: 2 additions & 2 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions server/python/plugin_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,13 @@ async def getServicePort(self, name):
raise Exception(f'unknown service {name}')

async def start_stats_runner(self):
pong = None
async def ping(time: int):
nonlocal pong
pong = pong or await self.peer.getParam('pong')
await pong(time)
self.peer.params['ping'] = ping

update_stats = await self.peer.getParam('updateStats')
if not update_stats:
print('host did not provide update_stats')
Expand Down
44 changes: 36 additions & 8 deletions server/src/plugin/plugin-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,38 @@ export class PluginHost {
// the plugin is expected to send process stats every 10 seconds.
// this can be used as a check for liveness.
let lastStats: number;
const statsInterval = setInterval(async () => {
this.peer.params.updateStats = (stats: any) => {
lastStats = Date.now();
this.stats = stats;
}

let lastPong: number;
this.peer.params.pong = (time: number) => {
lastPong = time;
};
(async () => {
try {
let pingPromise: Promise<any>
while (!this.killed) {
await sleep(30000);
if (this.killed)
return;
pingPromise ||= await this.peer.getParam('ping');
const ping = await pingPromise;
await ping(Date.now());
}
}
catch (e) {
logger.log('e', 'plugin ping failed. restarting.');
this.api.requestRestart();
}
})();

const healthInterval = setInterval(async () => {
const now = Date.now();
// plugin may take a while to install, so wait 10 minutes.
// after that, require 1 minute checkins.
if (!lastStats) {
if (!lastStats || !lastPong) {
if (now - startupTime > 10 * 60 * 1000) {
const logger = await this.api.getLogger(undefined);
logger.log('e', 'plugin failed to start in a timely manner. restarting.');
Expand All @@ -364,15 +391,16 @@ export class PluginHost {
}
if (!pluginDebug && (lastStats + 60000 < now)) {
const logger = await this.api.getLogger(undefined);
logger.log('e', 'plugin is unresponsive. restarting.');
logger.log('e', 'plugin is not reporting stats. restarting.');
this.api.requestRestart();
}
if (!pluginDebug && (lastPong + 60000 < now)) {
const logger = await this.api.getLogger(undefined);
logger.log('e', 'plugin is not responding to ping. restarting.');
this.api.requestRestart();
}
}, 60000);
this.peer.killed.finally(() => clearInterval(statsInterval));
this.peer.params.updateStats = (stats: any) => {
lastStats = Date.now();
this.stats = stats;
}
this.peer.killed.finally(() => clearInterval(healthInterval));
}

async createRpcIoPeer(socket: IOServerSocket, accessControls: AccessControls) {
Expand Down
6 changes: 6 additions & 0 deletions server/src/plugin/plugin-remote-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ export function startPluginRemote(mainFilename: string, pluginId: string, peerSe
// start the stats updater/watchdog after installation has finished, as that may take some time.
peer.getParam('updateStats').then(updateStats => startStatsUpdater(allMemoryStats, updateStats));

let pong: (time: number) => Promise<void>;
peer.params.ping = async (time: number) => {
pong ||= await peer.getParam('pong');
await pong(time);
};

const main = pluginReader('main.nodejs.js');
const script = main.toString();

Expand Down

0 comments on commit 69a3e11

Please sign in to comment.