Skip to content

Commit

Permalink
Merge pull request #5334 from wasmerio/feat/app-job-schema
Browse files Browse the repository at this point in the history
Implement app.yaml job schema
  • Loading branch information
Arshia001 authored Jan 14, 2025
2 parents 7f23611 + 00c2568 commit cfb9413
Show file tree
Hide file tree
Showing 8 changed files with 678 additions and 16 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

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

195 changes: 186 additions & 9 deletions docs/schema/generated/jsonschema/types/AppConfigV1.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@
"$ref": "#/definitions/HealthCheckV1"
}
},
"jobs": {
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/Job"
}
},
"locality": {
"description": "Location-related configuration for the app.",
"anyOf": [
Expand Down Expand Up @@ -143,9 +152,13 @@
"properties": {
"max_age": {
"description": "Maximum age of snapshots.\n\nFormat: 5m, 1h, 2d, ...\n\nAfter the specified time new snapshots will be created, and the old ones discarded.",
"type": [
"string",
"null"
"anyOf": [
{
"$ref": "#/definitions/PrettyDuration"
},
{
"type": "null"
}
]
},
"requests": {
Expand Down Expand Up @@ -246,6 +259,85 @@
}
}
},
"ExecutableJob": {
"type": "object",
"properties": {
"capabilities": {
"anyOf": [
{
"$ref": "#/definitions/ExecutableJobCompatibilityMapV1"
},
{
"type": "null"
}
]
},
"cli_args": {
"description": "CLI arguments passed to the runner. Only applicable for runners that accept CLI arguments.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"command": {
"description": "The command to run. Defaults to the package's entrypoint.",
"type": [
"string",
"null"
]
},
"env": {
"description": "Environment variables.",
"type": [
"object",
"null"
],
"additionalProperties": {
"type": "string"
}
},
"package": {
"description": "The package that contains the command to run. Defaults to the app config's package.",
"anyOf": [
{
"$ref": "#/definitions/PackageSource"
},
{
"type": "null"
}
]
},
"volumes": {
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/AppVolume"
}
}
}
},
"ExecutableJobCompatibilityMapV1": {
"type": "object",
"properties": {
"memory": {
"description": "Instance memory settings.",
"anyOf": [
{
"$ref": "#/definitions/AppConfigCapabilityMemoryV1"
},
{
"type": "null"
}
]
}
},
"additionalProperties": true
},
"HealthCheckHttpV1": {
"description": "Health check configuration for http endpoints.",
"type": "object",
Expand Down Expand Up @@ -309,9 +401,13 @@
},
"timeout": {
"description": "Request timeout.\n\nFormat: 1s, 5m, 11h, ...",
"type": [
"string",
"null"
"anyOf": [
{
"$ref": "#/definitions/PrettyDuration"
},
{
"type": "null"
}
]
},
"unhealthy_threshold": {
Expand Down Expand Up @@ -404,9 +500,13 @@
},
"timeout": {
"description": "Request timeout.\n\nFormat: 1s, 5m, 11h, ...",
"type": [
"string",
"null"
"anyOf": [
{
"$ref": "#/definitions/PrettyDuration"
},
{
"type": "null"
}
]
}
}
Expand Down Expand Up @@ -443,6 +543,80 @@
}
}
},
"Job": {
"description": "Job configuration.",
"type": "object",
"oneOf": [
{
"type": "object",
"required": [
"fetch"
],
"properties": {
"fetch": {
"$ref": "#/definitions/HttpRequest"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"execute"
],
"properties": {
"execute": {
"$ref": "#/definitions/ExecutableJob"
}
},
"additionalProperties": false
}
],
"required": [
"name",
"trigger"
],
"properties": {
"max_schedule_drift": {
"description": "Don't start job if past the due time by this amount, instead opting to wait for the next instance of it to be triggered.",
"anyOf": [
{
"$ref": "#/definitions/PrettyDuration"
},
{
"type": "null"
}
]
},
"name": {
"type": "string"
},
"retries": {
"type": [
"integer",
"null"
],
"format": "uint32",
"minimum": 0.0
},
"timeout": {
"anyOf": [
{
"$ref": "#/definitions/PrettyDuration"
},
{
"type": "null"
}
]
},
"trigger": {
"$ref": "#/definitions/JobTrigger"
}
}
},
"JobTrigger": {
"type": "string"
},
"Locality": {
"type": "object",
"required": [
Expand All @@ -460,6 +634,9 @@
"PackageSource": {
"type": "string"
},
"PrettyDuration": {
"type": "string"
},
"Redirect": {
"description": "App redirect configuration.",
"type": "object",
Expand Down
1 change: 1 addition & 0 deletions lib/cli/src/commands/app/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ impl CmdAppCreate {
locality: None,
redirect: None,
extra: HashMap::new(),
jobs: None,
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ schemars = { version = "0.8.16", features = ["url"] }
url = { version = "2.5.0", features = ["serde"] }
hex = "0.4.3"
ciborium = "0.2.2"
cron = { version = "0.14.0", features = ["serde"] }

[dev-dependencies]
pretty_assertions.workspace = true
Expand Down
4 changes: 3 additions & 1 deletion lib/config/src/app/http.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use super::pretty_duration::PrettyDuration;

/// Defines an HTTP request.
#[derive(
schemars::JsonSchema, serde::Serialize, serde::Deserialize, PartialEq, Eq, Clone, Debug,
Expand All @@ -24,7 +26,7 @@ pub struct HttpRequest {
///
/// Format: 1s, 5m, 11h, ...
#[serde(skip_serializing_if = "Option::is_none")]
pub timeout: Option<String>,
pub timeout: Option<PrettyDuration>,

#[serde(skip_serializing_if = "Option::is_none")]
pub expect: Option<HttpRequestExpect>,
Expand Down
Loading

0 comments on commit cfb9413

Please sign in to comment.