Skip to content

Commit

Permalink
feat: external resource check timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
zdm committed Dec 18, 2024
1 parent 345b76a commit ffb9399
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/external-resources/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import path from "node:path";
import stream from "node:stream";
import tar from "#lib/tar";

const DEFAULT_CHECK_TIMEOUT = 1000 * 60 * 60; // 1 hour

export default class ExternalResource extends Events {
#id;
#location;
Expand Down Expand Up @@ -68,6 +70,14 @@ export default class ExternalResource extends Events {
return this.#index?.meta;
}

get lastChecked () {
return this.#index.lastChecked;
}

get lastUpdated () {
return this.#index.lastUpdated;
}

// public
async check ( { remote = false, forceRemote } = {} ) {
const res = await this.update( {
Expand Down Expand Up @@ -97,6 +107,9 @@ export default class ExternalResource extends Events {
// resource is expired
if ( this.isExpired ) remote = true;

// last checked interval
if ( this.lastChecked && this.lastChecked + DEFAULT_CHECK_TIMEOUT < Date.now() ) remote = true;

// resource exists
if ( isInstalled && !remote ) return result( 304 );

Expand Down

0 comments on commit ffb9399

Please sign in to comment.