diff --git a/.gitignore b/.gitignore index 2220cf6..3ac8aeb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ target *.tar.gz trigger-cron.json -.spin \ No newline at end of file +.spin +venv +__pycache__ +*.wasm +spin_cron \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 44aa1bd..76bec1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4944,15 +4944,6 @@ version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" -[[package]] -name = "wasm-encoder" -version = "0.36.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "822b645bf4f2446b949776ffca47e2af60b167209ffb70814ef8779d299cd421" -dependencies = [ - "leb128", -] - [[package]] name = "wasm-encoder" version = "0.38.1" @@ -5034,16 +5025,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "wasmparser" -version = "0.116.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a58e28b80dd8340cb07b8242ae654756161f6fc8d0038123d679b7b99964fa50" -dependencies = [ - "indexmap 2.1.0", - "semver", -] - [[package]] name = "wasmparser" version = "0.118.1" @@ -5814,9 +5795,9 @@ dependencies = [ [[package]] name = "wit-bindgen" -version = "0.13.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38726c54a5d7c03cac28a2a8de1006cfe40397ddf6def3f836189033a413bc08" +checksum = "b76f1d099678b4f69402a421e888bbe71bf20320c2f3f3565d0e7484dbe5bc20" dependencies = [ "bitflags 2.4.1", "wit-bindgen-rust-macro", @@ -5824,33 +5805,33 @@ dependencies = [ [[package]] name = "wit-bindgen-core" -version = "0.13.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8bf1fddccaff31a1ad57432d8bfb7027a7e552969b6c68d6d8820dcf5c2371f" +checksum = "75d55e1a488af2981fb0edac80d8d20a51ac36897a1bdef4abde33c29c1b6d0d" dependencies = [ "anyhow", - "wit-component 0.17.0", - "wit-parser 0.12.2", + "wit-component 0.18.2", + "wit-parser 0.13.2", ] [[package]] name = "wit-bindgen-rust" -version = "0.13.2" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e7200e565124801e01b7b5ddafc559e1da1b2e1bed5364d669cd1d96fb88722" +checksum = "a01ff9cae7bf5736750d94d91eb8a49f5e3a04aff1d1a3218287d9b2964510f8" dependencies = [ "anyhow", "heck", "wasm-metadata 0.10.14", "wit-bindgen-core", - "wit-component 0.17.0", + "wit-component 0.18.2", ] [[package]] name = "wit-bindgen-rust-macro" -version = "0.13.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ae33920ad8119fe72cf59eb00f127c0b256a236b9de029a1a10397b1f38bdbd" +checksum = "804a98e2538393d47aa7da65a7348116d6ff403b426665152b70a168c0146d49" dependencies = [ "anyhow", "proc-macro2", @@ -5858,14 +5839,14 @@ dependencies = [ "syn 2.0.39", "wit-bindgen-core", "wit-bindgen-rust", - "wit-component 0.17.0", + "wit-component 0.18.2", ] [[package]] name = "wit-component" -version = "0.17.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "480cc1a078b305c1b8510f7c455c76cbd008ee49935f3a6c5fd5e937d8d95b1e" +checksum = "5b8a35a2a9992898c9d27f1664001860595a4bc99d32dd3599d547412e17d7e2" dependencies = [ "anyhow", "bitflags 2.4.1", @@ -5874,10 +5855,10 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "wasm-encoder 0.36.2", + "wasm-encoder 0.38.1", "wasm-metadata 0.10.14", - "wasmparser 0.116.1", - "wit-parser 0.12.2", + "wasmparser 0.118.1", + "wit-parser 0.13.2", ] [[package]] @@ -5899,23 +5880,6 @@ dependencies = [ "wit-parser 0.200.0", ] -[[package]] -name = "wit-parser" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43771ee863a16ec4ecf9da0fc65c3bbd4a1235c8e3da5f094b562894843dfa76" -dependencies = [ - "anyhow", - "id-arena", - "indexmap 2.1.0", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", -] - [[package]] name = "wit-parser" version = "0.13.2" diff --git a/Cargo.toml b/Cargo.toml index a46ee03..6bb6b9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,3 +27,6 @@ tokio-cron-scheduler = "0.9.4" tracing = { version = "0.1", features = ["log"] } tracing-subscriber = { version = "0.3.7", features = ["env-filter"] } wasmtime = { version = "18.0.1" } + +[workspace.dependencies] +wit-bindgen = "0.16.0" diff --git a/guest-python/README.md b/guest-python/README.md new file mode 100644 index 0000000..3cc88d3 --- /dev/null +++ b/guest-python/README.md @@ -0,0 +1,26 @@ +# Python Sample for Spin Cron Trigger + +## Setup Environment and Dependencies + +```bash +python3 -m venv venv +source activate venv/bin/activate +pip3 install -r requirements.txt +``` + +To generate bindings to use with intellisense + +```bash +componentize-py -d ../cron.wit -w spin-cron bindings bindings +mv binding/spin_cron ./ +rm -r bindings +``` + + +## Build and run the app + +```bash +$ spin up --build +[1710200677] Hello every 2s +[1710200679] Hello every 2s +``` \ No newline at end of file diff --git a/guest-python/app.py b/guest-python/app.py new file mode 100644 index 0000000..9b0220d --- /dev/null +++ b/guest-python/app.py @@ -0,0 +1,8 @@ +import spin_cron +from spin_cron.imports import cron_types +from spin_sdk import variables + +class SpinCron(spin_cron.SpinCron): + def handle_cron_event(self, metadata: cron_types.Metadata) -> None: + temp = variables.get("something") + print("[" + str(metadata.timestamp) +"] " + "Hello every " + temp) \ No newline at end of file diff --git a/guest-python/requirements.txt b/guest-python/requirements.txt new file mode 100644 index 0000000..92609de --- /dev/null +++ b/guest-python/requirements.txt @@ -0,0 +1,2 @@ +spin-sdk==2.0.0 +componentize-py==0.12.0 \ No newline at end of file diff --git a/guest-python/spin.toml b/guest-python/spin.toml new file mode 100644 index 0000000..f470bbc --- /dev/null +++ b/guest-python/spin.toml @@ -0,0 +1,18 @@ +spin_manifest_version = 2 + +[application] +name = "cron-sampl-py" +authors = ["Fermyon Engineering "] +description = "" +version = "0.1.0" + +[[trigger.cron]] +component = "every2seconds" +cron_expression = "1/2 * * * * *" + +[component.every2seconds] +source = "app.wasm" +[component.every2seconds.build] +command = "componentize-py -d ../cron.wit -w spin-cron componentize -m spin_sdk=spin-imports app -o app.wasm" +[component.every2seconds.variables] +something = "2s" diff --git a/guest/Cargo.lock b/guest-rust/Cargo.lock similarity index 91% rename from guest/Cargo.lock rename to guest-rust/Cargo.lock index 3a40718..2e26396 100644 --- a/guest/Cargo.lock +++ b/guest-rust/Cargo.lock @@ -181,6 +181,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "id-arena" version = "2.2.1" @@ -364,11 +375,10 @@ dependencies = [ [[package]] name = "spin-cron-macro" version = "0.1.0" -source = "git+https://github.com/fermyon/spin-trigger-cron/#d2ad231b0a772e6f1867a98e751e10bfb1d95fcc" dependencies = [ "anyhow", "bytes", - "http", + "http 0.2.11", "proc-macro2", "quote", "syn 1.0.109", @@ -378,7 +388,6 @@ dependencies = [ [[package]] name = "spin-cron-sdk" version = "0.1.0" -source = "git+https://github.com/fermyon/spin-trigger-cron/#d2ad231b0a772e6f1867a98e751e10bfb1d95fcc" dependencies = [ "spin-cron-macro", "wit-bindgen", @@ -386,12 +395,12 @@ dependencies = [ [[package]] name = "spin-macro" -version = "0.1.0" -source = "git+https://github.com/fermyon/spin?tag=v2.0.1#1d72f1c4244ecd8f7e0f150836565b18ef897e64" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a161ae2fefde8582ef555ead81d87cf897cd31a23a1d1e0c22a9c43fd9af421a" dependencies = [ "anyhow", "bytes", - "http", "proc-macro2", "quote", "syn 1.0.109", @@ -399,15 +408,16 @@ dependencies = [ [[package]] name = "spin-sdk" -version = "2.0.1" -source = "git+https://github.com/fermyon/spin?tag=v2.0.1#1d72f1c4244ecd8f7e0f150836565b18ef897e64" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2c02cf00c243c03fb330cb5be7bf4eb3c8db7c5476425068c7385ddff1567aa" dependencies = [ "anyhow", "async-trait", "bytes", "form_urlencoded", "futures", - "http", + "http 1.1.0", "once_cell", "routefinder", "serde", @@ -489,15 +499,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "wasm-encoder" -version = "0.36.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "822b645bf4f2446b949776ffca47e2af60b167209ffb70814ef8779d299cd421" -dependencies = [ - "leb128", -] - [[package]] name = "wasm-encoder" version = "0.38.1" @@ -519,18 +520,8 @@ dependencies = [ "serde_derive", "serde_json", "spdx", - "wasm-encoder 0.38.1", - "wasmparser 0.118.1", -] - -[[package]] -name = "wasmparser" -version = "0.116.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a58e28b80dd8340cb07b8242ae654756161f6fc8d0038123d679b7b99964fa50" -dependencies = [ - "indexmap", - "semver", + "wasm-encoder", + "wasmparser", ] [[package]] @@ -545,9 +536,9 @@ dependencies = [ [[package]] name = "wit-bindgen" -version = "0.13.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38726c54a5d7c03cac28a2a8de1006cfe40397ddf6def3f836189033a413bc08" +checksum = "b76f1d099678b4f69402a421e888bbe71bf20320c2f3f3565d0e7484dbe5bc20" dependencies = [ "bitflags", "wit-bindgen-rust-macro", @@ -555,9 +546,9 @@ dependencies = [ [[package]] name = "wit-bindgen-core" -version = "0.13.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8bf1fddccaff31a1ad57432d8bfb7027a7e552969b6c68d6d8820dcf5c2371f" +checksum = "75d55e1a488af2981fb0edac80d8d20a51ac36897a1bdef4abde33c29c1b6d0d" dependencies = [ "anyhow", "wit-component", @@ -566,9 +557,9 @@ dependencies = [ [[package]] name = "wit-bindgen-rust" -version = "0.13.2" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e7200e565124801e01b7b5ddafc559e1da1b2e1bed5364d669cd1d96fb88722" +checksum = "a01ff9cae7bf5736750d94d91eb8a49f5e3a04aff1d1a3218287d9b2964510f8" dependencies = [ "anyhow", "heck", @@ -579,9 +570,9 @@ dependencies = [ [[package]] name = "wit-bindgen-rust-macro" -version = "0.13.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ae33920ad8119fe72cf59eb00f127c0b256a236b9de029a1a10397b1f38bdbd" +checksum = "804a98e2538393d47aa7da65a7348116d6ff403b426665152b70a168c0146d49" dependencies = [ "anyhow", "proc-macro2", @@ -594,9 +585,9 @@ dependencies = [ [[package]] name = "wit-component" -version = "0.17.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "480cc1a078b305c1b8510f7c455c76cbd008ee49935f3a6c5fd5e937d8d95b1e" +checksum = "5b8a35a2a9992898c9d27f1664001860595a4bc99d32dd3599d547412e17d7e2" dependencies = [ "anyhow", "bitflags", @@ -605,17 +596,17 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "wasm-encoder 0.36.2", + "wasm-encoder", "wasm-metadata", - "wasmparser 0.116.1", + "wasmparser", "wit-parser", ] [[package]] name = "wit-parser" -version = "0.12.2" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43771ee863a16ec4ecf9da0fc65c3bbd4a1235c8e3da5f094b562894843dfa76" +checksum = "316b36a9f0005f5aa4b03c39bc3728d045df136f8c13a73b7db4510dec725e08" dependencies = [ "anyhow", "id-arena", diff --git a/guest/Cargo.toml b/guest-rust/Cargo.toml similarity index 55% rename from guest/Cargo.toml rename to guest-rust/Cargo.toml index 3e7f0f4..7985cdf 100644 --- a/guest/Cargo.toml +++ b/guest-rust/Cargo.toml @@ -9,7 +9,7 @@ rust-version = "1.71" crate-type = ["cdylib"] [dependencies] -spin-sdk = { git = "https://github.com/fermyon/spin", tag = "v2.0.1" } -spin-cron-sdk = { git = "https://github.com/fermyon/spin-trigger-cron/" } +spin-sdk = "3.0.0" +spin-cron-sdk = { path = "../sdk" } -[workspace] \ No newline at end of file +[workspace] diff --git a/guest/spin.toml b/guest-rust/spin.toml similarity index 100% rename from guest/spin.toml rename to guest-rust/spin.toml diff --git a/guest/src/lib.rs b/guest-rust/src/lib.rs similarity index 100% rename from guest/src/lib.rs rename to guest-rust/src/lib.rs diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 198c3cc..f0ecb8d 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -11,4 +11,4 @@ name = "spin_cron_sdk" [dependencies] spin-cron-macro = { path = "macro" } -wit-bindgen = "0.13.1" +wit-bindgen = { workspace = true } diff --git a/sdk/macro/Cargo.toml b/sdk/macro/Cargo.toml index 653455e..962204b 100644 --- a/sdk/macro/Cargo.toml +++ b/sdk/macro/Cargo.toml @@ -16,4 +16,4 @@ http = "0.2" proc-macro2 = "1" quote = "1.0" syn = { version = "1.0", features = ["full"] } -wit-bindgen = "0.13.1" +wit-bindgen = { workspace = true } diff --git a/templates/cron-rust/content/Cargo.toml b/templates/cron-rust/content/Cargo.toml index ed6784a..e588e8c 100644 --- a/templates/cron-rust/content/Cargo.toml +++ b/templates/cron-rust/content/Cargo.toml @@ -10,7 +10,7 @@ rust-version = "1.71" crate-type = ["cdylib"] [dependencies] -spin-sdk = { git = "https://github.com/fermyon/spin", tag = "v2.0.1" } +spin-sdk = "3.0.0" spin-cron-sdk = { git = "https://github.com/fermyon/spin-trigger-cron/" } [workspace]