Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
target
*.tar.gz
trigger-cron.json
.spin
.spin
venv
__pycache__
*.wasm
spin_cron
70 changes: 17 additions & 53 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
26 changes: 26 additions & 0 deletions guest-python/README.md
Original file line number Diff line number Diff line change
@@ -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
```
8 changes: 8 additions & 0 deletions guest-python/app.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions guest-python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
spin-sdk==2.0.0
componentize-py==0.12.0
18 changes: 18 additions & 0 deletions guest-python/spin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
spin_manifest_version = 2

[application]
name = "cron-sampl-py"
authors = ["Fermyon Engineering <engineering@fermyon.com>"]
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"
Loading