Skip to content

Commit

Permalink
Merge pull request #62 from Hexagon/dev
Browse files Browse the repository at this point in the history
1.0.3 stable
  • Loading branch information
Hexagon authored Nov 6, 2024
2 parents d28bfd6 + b37733e commit d10219e
Show file tree
Hide file tree
Showing 20 changed files with 100 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github: [hexagon]
ko_fi: hexagon_56k
ko_fi: hexagon_56k
2 changes: 1 addition & 1 deletion .github/workflows/deno.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
deno-version: [1.43.3, "v1.x"]
deno-version: [1.43.3, "v1.x", "v2.x"]

steps:
- name: Git Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/jsr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ jobs:
permissions:
contents: read
id-token: write
uses: cross-org/workflows/.github/workflows/jsr-publish.yml@main
uses: cross-org/workflows/.github/workflows/jsr-publish.yml@main
2 changes: 1 addition & 1 deletion .github/workflows/pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v2
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ deno run -Ar jsr:@pup/pup setup

This command downloads the latest version of Pup and installs it on your system. Read more about release channels [here](https://pup.56k.guru/installation/#release-channels).

> **Note** If you're using Windows, automated setup may fail. If so, follow the instructions at the command line.
### Configuration and Usage

Pup revolves around instance configuration files, where each managed process belongs to an instance defined by a `pup.json`. This file can either be created manually, or by the command line helpers
Expand Down
2 changes: 1 addition & 1 deletion application.meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

const Application = {
name: "pup",
version: "1.0.2",
version: "1.0.3",
url: "jsr:@pup/pup@$VERSION",
description: "Powerful universal process manager, designed to keep your scripts, applications and services alive.",
canary_url: "https://raw.githubusercontent.com/Hexagon/pup/refs/heads/dev/pup.ts",
Expand Down
8 changes: 4 additions & 4 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pup/pup",
"version": "1.0.2",
"version": "1.0.3",

"exports": {
".": "./pup.ts",
Expand All @@ -26,7 +26,7 @@

"tasks": {
"check-deps": "deno run -r --allow-read=. --allow-net=jsr.io,registry.npmjs.org jsr:@check/deps",
"check": "deno fmt --check && deno lint && deno check pup.ts && deno test --trace-leaks --allow-read --allow-write --allow-env --allow-net --allow-sys --allow-run --coverage=cov_profile && echo \"Generating coverage\" && deno coverage cov_profile --exclude=pup/test --lcov --output=cov_profile.lcov",
"check": "deno fmt --check && deno lint && deno test --trace-leaks --allow-read --allow-write --allow-env --allow-net --allow-sys --allow-run --coverage=cov_profile && echo \"Generating coverage\" && deno coverage cov_profile --exclude=pup/test --lcov --output=cov_profile.lcov",
"check-coverage": "deno task check && genhtml cov_profile.lcov --output-directory cov_profile/html && lcov --list cov_profile.lcov && deno run --allow-net --allow-read https://deno.land/std/http/file_server.ts cov_profile/html",
"build-schema": "deno run --allow-write --allow-read --allow-env=XDG_DATA_HOME,HOME tools/build-schema.ts && deno fmt",
"build-versions": "deno run --allow-read --allow-write --allow-env tools/release.ts && deno fmt",
Expand All @@ -42,10 +42,10 @@
"@cross/jwt": "jsr:@cross/jwt@~0.5.0",
"@cross/kv": "jsr:@cross/kv@~0.17.1",
"@cross/runtime": "jsr:@cross/runtime@~1.1.0",
"@cross/service": "jsr:@cross/service@~1.0.3",
"@cross/service": "jsr:@cross/service@~1.0.5",
"@cross/test": "jsr:@cross/test@~0.0.9",
"@cross/utils": "jsr:@cross/utils@^0.16.0",
"@hexagon/croner": "jsr:@hexagon/croner@~8.1.0",
"@hexagon/croner": "jsr:@hexagon/croner@~9.0.0",
"@oak/oak": "jsr:@oak/oak@^17.0.0",
"@pup/api-client": "jsr:@pup/api-client@~2.0.0",
"@pup/api-definitions": "jsr:@pup/api-definitions@~2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion docs/src/_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description": "Universal Process Manager"
},
"substitute": {
"$PUP_VERSION": "1.0.2"
"$PUP_VERSION": "1.0.3"
},
"top_links": [
{
Expand Down
6 changes: 6 additions & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ nav_order: 13

All notable changes to this project will be documented in this section.

## [1.0.3] - 2024-11-06

- fix(core): Fix service installation on Windows by upgrading dependency @cross/service
- fix(cli): Add notes on how to recover from a failed install on Windows
- chore(deps): Fixes for Deno 2

## [1.0.2] - 2024-09-25

- fix(core): Fix `--canary` install base url
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export async function upgrade(
}
exit(0)
} else {
console.log(`\n${upgradeOrDowngradingAction} failed.\n`)
console.log(`\n${upgradeOrDowngradingAction} automatically failed! Try running the installation command manually: \n\ndeno ${installCmd.join(" ")}\n`)
exit(1)
}
}
6 changes: 3 additions & 3 deletions lib/core/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Cluster extends Process {
)
}

public isCluster = (): boolean => {
public override isCluster = (): boolean => {
return true
}

Expand Down Expand Up @@ -141,7 +141,7 @@ class Cluster extends Process {
return this.processes.map((process) => process.getStatus())
}

public getStatus(): ProcessInformation {
public override getStatus(): ProcessInformation {
const clusterStatus: ProcessInformation = {
id: this.getConfig().id,
status: ApiProcessState.CREATED,
Expand Down Expand Up @@ -175,7 +175,7 @@ class Cluster extends Process {
return clusterStatus
}

public cleanup = (): void => {
public override cleanup = (): void => {
this.loadBalancerWorker?.terminate()
this.loadBalancerWorker = null
}
Expand Down
3 changes: 2 additions & 1 deletion lib/core/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ const ConfigurationSchema = z.object({
function validateConfiguration(unsafeConfiguration: unknown): Configuration {
try {
ConfigurationSchema.parse(unsafeConfiguration)
} catch (e) {
// deno-lint-ignore no-explicit-any
} catch (e: any) {
throw new Error(e.errors[0]?.message)
}
return unsafeConfiguration as Configuration
Expand Down
42 changes: 21 additions & 21 deletions lib/core/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface LogEventData {
timeStamp: number
}

type AttachedLogger = (severity: string, category: string, text: string, process?: ProcessConfiguration, timeStamp?: number) => boolean
type AttachedLogger = (severity: string, category: string, text: string, processConf?: ProcessConfiguration, timeStamp?: number) => boolean

class Logger {
private config: GlobalLoggerConfiguration = {}
Expand Down Expand Up @@ -106,9 +106,9 @@ class Logger {
return await this.getLogContents(processId, startTimeStamp, endTimeStamp, undefined, nRows)
}

private async internalLog(severity: string, category: string, text: string, process?: ProcessConfiguration, timeStamp?: number) {
private async internalLog(severity: string, category: string, text: string, processConf?: ProcessConfiguration, timeStamp?: number) {
// Default initiator to core
const initiator = process?.id || "core"
const initiator = processConf?.id || "core"

timeStamp = timeStamp || Date.now()

Expand Down Expand Up @@ -136,7 +136,7 @@ class Logger {
if (this.attachedLogger) {
// Do not trust the attached logger
try {
blockedByAttachedLogger = this.attachedLogger(severity, category, text, process, timeStamp)
blockedByAttachedLogger = this.attachedLogger(severity, category, text, processConf, timeStamp)
} catch (e) {
console.error("Error in attached logger: ", e)
}
Expand All @@ -146,7 +146,7 @@ class Logger {
if (blockedByAttachedLogger) return

// Log to console
const logToConsoleProcess = (process?.logger?.console ?? true) === false
const logToConsoleProcess = (processConf?.logger?.console ?? true) === false
const logToConsoleGlobal = (this.config?.console ?? true) === false
const logToConsole = !logToConsoleGlobal && !logToConsoleProcess
const isStdErr = severity === "error" || category === "stderr"
Expand Down Expand Up @@ -196,14 +196,14 @@ class Logger {
}

// Write process log file(s)
const decorateProcessFiles = process?.logger?.decorateFiles ?? false
const decorateProcessFiles = processConf?.logger?.decorateFiles ?? false
// If stderr is not defined but stdout is, use the stdout file
const stderrProcessFileName = process?.logger?.stderr ?? process?.logger?.stdout
const stderrProcessFileName = processConf?.logger?.stderr ?? processConf?.logger?.stdout
if (isStdErr && stderrProcessFileName) {
this.writeFile(stderrProcessFileName, decorateProcessFiles ? decoratedLogText : text)
}
if (!isStdErr && process?.logger?.stdout) {
this.writeFile(process?.logger?.stdout, decorateProcessFiles ? decoratedLogText : text)
if (!isStdErr && processConf?.logger?.stdout) {
this.writeFile(processConf?.logger?.stdout, decorateProcessFiles ? decoratedLogText : text)
}
}

Expand All @@ -217,25 +217,25 @@ class Logger {
}
}

public async generic(severity: string, category: string, text: string, process?: ProcessConfiguration, timestamp?: number) {
public async generic(severity: string, category: string, text: string, processConf?: ProcessConfiguration, timestamp?: number) {
if (severity === "log" || severity === "info" || severity === "warn" || severity === "error") {
await this.internalLog(severity, category, text, process, timestamp)
await this.internalLog(severity, category, text, processConf, timestamp)
} else {
this.warn("logger", "Log with invalid severity received, text: ${text}")
}
}

public async log(category: string, text: string, process?: ProcessConfiguration, timestamp?: number) {
await this.internalLog("log", category, text, process, timestamp)
public async log(category: string, text: string, processConf?: ProcessConfiguration, timestamp?: number) {
await this.internalLog("log", category, text, processConf, timestamp)
}
public async info(category: string, text: string, process?: ProcessConfiguration, timestamp?: number) {
await this.internalLog("info", category, text, process, timestamp)
public async info(category: string, text: string, processConf?: ProcessConfiguration, timestamp?: number) {
await this.internalLog("info", category, text, processConf, timestamp)
}
public async warn(category: string, text: string, process?: ProcessConfiguration, timestamp?: number) {
await this.internalLog("warn", category, text, process, timestamp)
public async warn(category: string, text: string, processConf?: ProcessConfiguration, timestamp?: number) {
await this.internalLog("warn", category, text, processConf, timestamp)
}
public async error(category: string, text: string, process?: ProcessConfiguration, timestamp?: number) {
await this.internalLog("error", category, text, process, timestamp)
public async error(category: string, text: string, processConf?: ProcessConfiguration, timestamp?: number) {
await this.internalLog("error", category, text, processConf, timestamp)
}
public async purge(keepHours: number): Promise<number> {
if (!this.kv?.isOpen()) {
Expand All @@ -254,7 +254,7 @@ class Logger {
await this.kv.defer(this.kv.vacuum())
return rowsDeleted
} catch (error) {
this.log("error", `Failed to purge logs from store '${this.storeName}': ${error.message}`)
this.log("error", `Failed to purge logs from store '${this.storeName}': ${error instanceof Error ? error.message : "Unknown"}`)
return 0
}
}
Expand All @@ -265,7 +265,7 @@ class Logger {
try {
await this.kv?.close(timeoutMs)
} catch (e) {
console.error("Error while closing kv store: " + e.message)
console.error("Error while closing kv store: " + (e instanceof Error ? e.message : "Unknown"))
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/core/pup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ class Pup {
this.logger.log("plugins", `Loading plugin from '${plugin.url}'`)
await newPlugin.load()
} catch (e) {
this.logger.error("plugins", `Failed to load plugin '${plugin.url}: ${e.message}'`)
this.logger.error("plugins", `Failed to load plugin '${plugin.url}: ${e instanceof Error ? e.message : "Unknown"}'`)
success = false
}
try {
this.logger.log("plugins", `Verifying plugin from '${plugin.url}'`)
newPlugin.verify()
} catch (e) {
this.logger.error("plugins", `Failed to verify plugin '${plugin.url}': ${e.message}`)
this.logger.error("plugins", `Failed to verify plugin '${plugin.url}': ${e instanceof Error ? e.message : "Unknown"}`)
success = false
}
if (success) {
Expand Down Expand Up @@ -308,7 +308,7 @@ class Pup {
}
}
} catch (e) {
this.logger.error("watchdog", "Watchdog error: ", e)
this.logger.error("watchdog", "Watchdog error: " + (e instanceof Error ? e.message : "Unknown"))
}

// Update process status
Expand Down Expand Up @@ -374,7 +374,7 @@ class Pup {
} catch (e) {
this.logger.error(
"rest",
`An error occured while inizializing the rest api: ${e.message}`,
`An error occured while inizializing the rest api: ${e instanceof Error ? e.message : "Unknown"}`,
)
}
}
Expand Down
24 changes: 12 additions & 12 deletions lib/core/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class RestApi {
ctx.response.status = Status.OK
} catch (err) {
ctx.response.status = Status.InternalServerError
ctx.response.body = { error: err.message }
ctx.response.body = { error: err instanceof Error ? err.message : "Unknown" }
}
})
.get("/state", (ctx) => {
Expand All @@ -164,7 +164,7 @@ export class RestApi {
ctx.response.status = Status.OK
} catch (err) {
ctx.response.status = Status.InternalServerError
ctx.response.body = { error: err.message }
ctx.response.body = { error: err instanceof Error ? err.message : "Unknown" }
}
})
.post("/processes/:id/start", (ctx) => {
Expand All @@ -179,7 +179,7 @@ export class RestApi {
ctx.response.status = Status.OK
} catch (err) {
ctx.response.status = Status.InternalServerError
ctx.response.body = { error: err.message }
ctx.response.body = { error: err instanceof Error ? err.message : "Unknown" }
}
})
.post("/processes/:id/stop", async (ctx) => {
Expand All @@ -194,7 +194,7 @@ export class RestApi {
ctx.response.status = Status.OK
} catch (err) {
ctx.response.status = Status.InternalServerError
ctx.response.body = { error: err.message }
ctx.response.body = { error: err instanceof Error ? err.message : "Unknown" }
}
})
.post("/processes/:id/restart", (ctx) => {
Expand All @@ -209,7 +209,7 @@ export class RestApi {
ctx.response.status = Status.OK
} catch (err) {
ctx.response.status = Status.InternalServerError
ctx.response.body = { error: err.message }
ctx.response.body = { error: err instanceof Error ? err.message : "Unknown" }
}
})
.post("/processes/:id/block", (ctx) => {
Expand All @@ -224,7 +224,7 @@ export class RestApi {
ctx.response.status = Status.OK
} catch (err) {
ctx.response.status = Status.InternalServerError
ctx.response.body = { error: err.message }
ctx.response.body = { error: err instanceof Error ? err.message : "Unknown" }
}
})
.post("/processes/:id/unblock", (ctx) => {
Expand All @@ -239,7 +239,7 @@ export class RestApi {
ctx.response.status = Status.OK
} catch (err) {
ctx.response.status = Status.InternalServerError
ctx.response.body = { error: err.message }
ctx.response.body = { error: err instanceof Error ? err.message : "Unknown" }
}
})
.post("/telemetry", async (ctx) => {
Expand All @@ -255,7 +255,7 @@ export class RestApi {
}
} catch (err) {
ctx.response.status = Status.InternalServerError
ctx.response.body = { error: err.message }
ctx.response.body = { error: err instanceof Error ? err.message : "Unknown" }
}
}
})
Expand Down Expand Up @@ -285,7 +285,7 @@ export class RestApi {
}
} catch (err) {
ctx.response.status = Status.InternalServerError
ctx.response.body = { error: err.message }
ctx.response.body = { error: err instanceof Error ? err.message : "Unknown" }
}
}
})
Expand All @@ -295,7 +295,7 @@ export class RestApi {
ctx.response.status = Status.OK
} catch (err) {
ctx.response.status = Status.InternalServerError
ctx.response.body = { error: err.message }
ctx.response.body = { error: err instanceof Error ? err.message : "Unknown" }
}
})
.post("/log", async (ctx) => {
Expand Down Expand Up @@ -328,7 +328,7 @@ export class RestApi {
ctx.response.status = Status.Created
} catch (err) {
ctx.response.status = Status.InternalServerError
ctx.response.body = { error: err.message }
ctx.response.body = { error: err instanceof Error ? err.message : "Unknown" }
}
})
.get("/logs", async (context) => {
Expand Down Expand Up @@ -388,7 +388,7 @@ export class RestApi {
context.response.status = 500
context.response.body = {
error: "Internal Server Error",
message: error.message,
message: error instanceof Error ? error.message : "Unknown",
}
}
})
Expand Down
Loading

0 comments on commit d10219e

Please sign in to comment.