Skip to content

Commit c09fa67

Browse files
authored
add python sample, update templates and bump rust deps (#6)
add python sample, update templates and bump rust deps Signed-off-by: karthik2804 <[email protected]>
1 parent 3f10944 commit c09fa67

File tree

14 files changed

+120
-104
lines changed

14 files changed

+120
-104
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
target
22
*.tar.gz
33
trigger-cron.json
4-
.spin
4+
.spin
5+
venv
6+
__pycache__
7+
*.wasm
8+
spin_cron

Cargo.lock

Lines changed: 17 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ tokio-cron-scheduler = "0.9.4"
2727
tracing = { version = "0.1", features = ["log"] }
2828
tracing-subscriber = { version = "0.3.7", features = ["env-filter"] }
2929
wasmtime = { version = "18.0.1" }
30+
31+
[workspace.dependencies]
32+
wit-bindgen = "0.16.0"

guest-python/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Python Sample for Spin Cron Trigger
2+
3+
## Setup Environment and Dependencies
4+
5+
```bash
6+
python3 -m venv venv
7+
source activate venv/bin/activate
8+
pip3 install -r requirements.txt
9+
```
10+
11+
To generate bindings to use with intellisense
12+
13+
```bash
14+
componentize-py -d ../cron.wit -w spin-cron bindings bindings
15+
mv binding/spin_cron ./
16+
rm -r bindings
17+
```
18+
19+
20+
## Build and run the app
21+
22+
```bash
23+
$ spin up --build
24+
[1710200677] Hello every 2s
25+
[1710200679] Hello every 2s
26+
```

guest-python/app.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import spin_cron
2+
from spin_cron.imports import cron_types
3+
from spin_sdk import variables
4+
5+
class SpinCron(spin_cron.SpinCron):
6+
def handle_cron_event(self, metadata: cron_types.Metadata) -> None:
7+
temp = variables.get("something")
8+
print("[" + str(metadata.timestamp) +"] " + "Hello every " + temp)

guest-python/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
spin-sdk==2.0.0
2+
componentize-py==0.12.0

guest-python/spin.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
spin_manifest_version = 2
2+
3+
[application]
4+
name = "cron-sampl-py"
5+
authors = ["Fermyon Engineering <[email protected]>"]
6+
description = ""
7+
version = "0.1.0"
8+
9+
[[trigger.cron]]
10+
component = "every2seconds"
11+
cron_expression = "1/2 * * * * *"
12+
13+
[component.every2seconds]
14+
source = "app.wasm"
15+
[component.every2seconds.build]
16+
command = "componentize-py -d ../cron.wit -w spin-cron componentize -m spin_sdk=spin-imports app -o app.wasm"
17+
[component.every2seconds.variables]
18+
something = "2s"

0 commit comments

Comments
 (0)