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
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ This keeps the default quickstart untouched, avoids collisions with language
directory names, and lets a future `--use-case` path builder reuse the existing
overlay of shared and package-manager directories with a different root.

The first use case is `scheduled`, a Go template at
`templates/use-cases/scheduled/go/`, with a generated example at
`examples/use-cases/scheduled/go/`. It registers a cron schedule with the Go
SDK `WithWorkflowCron` option. The `--use-case` flag itself lives in the main
Hatchet CLI and is not part of this repo yet.
The first use case is `scheduled`, with templates for Go, Python, and
TypeScript under `templates/use-cases/scheduled/` and generated examples under
`examples/use-cases/scheduled/`. Each language registers a cron schedule with
its SDK (`WithWorkflowCron` in Go, `on_crons` in Python, the `on` cron option
in TypeScript) and defines a `manual-run` trigger for on-demand runs. The
`--use-case` flag itself lives in the main Hatchet CLI.
4 changes: 3 additions & 1 deletion cmd/generate-examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ type variant struct {
}

// poetry and pnpm are the generated package-manager variants because their
// templates carry lockfiles. scheduled-go is the first use-case variant.
// templates carry lockfiles.
var variants = []variant{
{name: "simple-go", language: "go", packageManager: "go", outputDir: "simple-go"},
{name: "simple-python", language: "python", packageManager: "poetry", outputDir: "simple-python"},
{name: "simple-typescript", language: "typescript", packageManager: "pnpm", outputDir: "simple-typescript"},
{name: "scheduled-go", language: "go", packageManager: "go", useCase: "scheduled", outputDir: filepath.Join("use-cases", "scheduled", "go")},
{name: "scheduled-python", language: "python", packageManager: "poetry", useCase: "scheduled", outputDir: filepath.Join("use-cases", "scheduled", "python")},
{name: "scheduled-typescript", language: "typescript", packageManager: "pnpm", useCase: "scheduled", outputDir: filepath.Join("use-cases", "scheduled", "typescript")},
}

const examplesDir = "examples"
Expand Down
3 changes: 0 additions & 3 deletions examples/simple-python/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ env/
.env
.env.local

# Poetry
poetry.lock

# OS
.DS_Store
Thumbs.db
6 changes: 0 additions & 6 deletions examples/simple-typescript/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,3 @@ logs/
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Lock files (package manager specific)
package-lock.json
yarn.lock
pnpm-lock.yaml
bun.lockb
42 changes: 42 additions & 0 deletions examples/use-cases/scheduled/python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Virtual Environment
.venv/
venv/
ENV/
env/

# IDEs
.vscode/
.idea/
*.swp
*.swo
*~

# Environment files
.env
.env.local

# OS
.DS_Store
Thumbs.db
16 changes: 16 additions & 0 deletions examples/use-cases/scheduled/python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3.11-slim

WORKDIR /app
# Install Poetry
RUN pip install poetry

# Copy dependency files
COPY pyproject.toml poetry.lock ./

# Install dependencies
RUN poetry config virtualenvs.create false && poetry install --no-root --only main

# Copy source code
COPY src ./src

CMD ["poetry", "run", "python", "src/worker.py"]
53 changes: 53 additions & 0 deletions examples/use-cases/scheduled/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Hatchet Scheduled Workflow Example

This is an example project demonstrating a scheduled Hatchet workflow in
Python. The worker registers the task with a cron schedule through `on_crons`,
so it runs every five minutes. You can also run it on demand. For detailed
setup instructions, see the [Hatchet Setup Guide](https://docs.hatchet.run/home/setup).

## Prerequisites

Before running this project, make sure you have the following:

1. [Python v3.10 or higher](https://www.python.org/downloads/)
2. [Poetry](https://python-poetry.org/docs/#installation) for dependency management

## Setup

1. Create the project using the Hatchet CLI:

```bash
hatchet quickstart --use-case scheduled --language python
```

2. Set the required environment variable `HATCHET_CLIENT_TOKEN` created in the [Getting Started Guide](https://docs.hatchet.run/home/hatchet-cloud-quickstart).

```bash
export HATCHET_CLIENT_TOKEN=<token>
```

> Note: If you're self hosting you may need to set `HATCHET_CLIENT_TLS_STRATEGY=none` to disable TLS

3. Install the project dependencies:

```bash
poetry install
```

### Running an example

1. Start a Hatchet worker:

```shell
poetry run python src/worker.py
```

The worker runs the task on its cron schedule while it is connected.

2. To run the task on demand, open a new terminal and run:

```shell
poetry run python src/run.py
```

This triggers the task on the worker running in the first terminal and prints the output to the second terminal.
Empty file.
12 changes: 12 additions & 0 deletions examples/use-cases/scheduled/python/hatchet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
dev:
preCmds: ["poetry install"]
runCmd: "poetry run python src/worker.py"
files:
- "**/*.py"
- "!**/__pycache__/**"
- "!.venv/**"
reload: true
triggers:
- name: "manual-run"
command: "poetry run python src/run.py"
description: "Run the scheduled workflow once on demand"
Loading