anbaric-cloud-hosting 1.65.3 → 1.66.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/main.ts CHANGED
@@ -160,7 +160,10 @@ if (buildLayer && process.env.ANBARIC_TENANT && process.env.ANBARIC_CLI_KEY_LOOK
160
160
  process.env.ANBARIC_CLI_KEY_LOOKUP_URL,
161
161
  process.env.ANBARIC_CLI_KEY_LOOKUP_SECRET ?? "",
162
162
  process.env.ANBARIC_TENANT,
163
- () => buildLayer.list().filter(app => app.status === "running" || app.status === "draining").length,
163
+ () => {
164
+ const live = buildLayer.list().filter(app => app.status === "running" || app.status === "draining");
165
+ return { apps: live.length, large: live.filter(app => app.size === "large").length };
166
+ },
164
167
  ).start();
165
168
  }
166
169
 
@@ -1,6 +1,7 @@
1
1
  type FetchFn = (url : string, init : RequestInit) => Promise<Response>;
2
2
 
3
- type CountApps = () => number;
3
+ // How many apps are running, and how many of those are on a large instance.
4
+ type CountApps = () => { apps : number, large : number };
4
5
 
5
6
  const REPORT_INTERVAL_MS = 60 * 60_000;
6
7
 
@@ -36,7 +37,7 @@ class UsageReporter {
36
37
  const response = await this.fetchFn(`${this.centralUrl}/usage`, {
37
38
  method: "POST",
38
39
  headers: { "content-type": "application/json", "x-anbaric-central-key": this.secret },
39
- body: JSON.stringify({ slug: this.tenantSlug, apps: this.countApps(), day: this.today() }),
40
+ body: JSON.stringify({ slug: this.tenantSlug, ...this.counted(), day: this.today() }),
40
41
  });
41
42
  if (! response.ok) console.warn(`[usage] central answered ${response.status} to the app count`);
42
43
  return response.ok;
@@ -46,6 +47,11 @@ class UsageReporter {
46
47
  }
47
48
  }
48
49
 
50
+ private counted() : { apps : number, largeApps : number } {
51
+ const { apps, large } = this.countApps();
52
+ return { apps, largeApps: large };
53
+ }
54
+
49
55
  // The day in UTC, so every tenant's day starts at the same moment however
50
56
  // the platform's clock is set.
51
57
  private today() : string {