mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2025-12-18 23:30:13 -06:00
Fix: Auto-generate docs snippets and examples (#2139)
* fix: gitignore all the generated stuff
* debug: try fixing build
* debug: build error part ii
* debug: move more deps out of dev
* fix: lock
* debug: lockfile
* fix: make dir
* fix: ci
* fix: dir
* debug: sed
* fix: sed
* debug: allow skipping
* Revert "debug: allow skipping"
This reverts commit 88e0ff870d.
* debug: ci
* fix: corepack
* debug: dir
* debug: sed
* debug: path
* fix: rm sync docs for now
* fix: remove more stuff
* fix: rm unused stuff
* fix: rm copy:app
* chore: lint
* fix: rm prettier from boot
* fix: couple missing scripts
* feat: auto-gen examples on push to main
* debug: test on this branch
* fix: install pnpm
* fix: cd
* fix: cmd
* Auto-generate files after merge [skip ci]
* fix: only copy examples
* debug: dummy commit for examples check
* chore: regenerate examples
* fix: naming
* fix: unwind dummy
* fix: only run on main
* fix: pre commit
* fix: naming
* chore: gen, fix task pre
* feat: create pr
* feat: only push examples changes
* fix: don't run from this branch
* fix: regen lockfile
* fix: regen docs lockfile
---------
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
6
.github/workflows/docs.yml
vendored
6
.github/workflows/docs.yml
vendored
@@ -23,6 +23,9 @@ jobs:
|
||||
- name: Install dependencies
|
||||
working-directory: frontend/docs
|
||||
run: pnpm install --frozen-lockfile
|
||||
- name: Generate snippets
|
||||
working-directory: frontend/snips
|
||||
run: pnpm install --frozen-lockfile && pnpm generate && pnpm run copy:docs
|
||||
- name: Lint
|
||||
working-directory: frontend/docs
|
||||
run: npm run lint:check
|
||||
@@ -45,6 +48,9 @@ jobs:
|
||||
- name: Install dependencies
|
||||
working-directory: frontend/docs
|
||||
run: pnpm install --frozen-lockfile
|
||||
- name: Generate snippets
|
||||
working-directory: frontend/snips
|
||||
run: pnpm install --frozen-lockfile && pnpm generate && pnpm run copy:docs
|
||||
- name: Build
|
||||
working-directory: frontend/docs
|
||||
run: npm run build
|
||||
|
||||
80
.github/workflows/gen-examples.yml
vendored
Normal file
80
.github/workflows/gen-examples.yml
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
name: generate examples
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
|
||||
jobs:
|
||||
generate:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '22'
|
||||
|
||||
- uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 10
|
||||
|
||||
- name: Generate
|
||||
working-directory: frontend/snips
|
||||
run: pnpm i && pnpm generate && pnpm run copy:examples
|
||||
|
||||
- name: Check for changes in examples directory
|
||||
id: verify-changed-files
|
||||
run: |
|
||||
# Check if there are any changes
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
CHANGED_FILES=$(git status --porcelain | awk '{print $2}')
|
||||
NON_EXAMPLES_CHANGES=$(echo "$CHANGED_FILES" | grep -v "^examples/" || true)
|
||||
|
||||
if [ -n "$NON_EXAMPLES_CHANGES" ]; then
|
||||
echo "Error: Changes detected outside of examples directory:"
|
||||
echo "$NON_EXAMPLES_CHANGES"
|
||||
echo "changed=false" >> $GITHUB_OUTPUT
|
||||
exit 1
|
||||
else
|
||||
echo "changed=true" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
else
|
||||
echo "changed=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Create branch and commit changes
|
||||
if: steps.verify-changed-files.outputs.changed == 'true'
|
||||
run: |
|
||||
git config --local user.email "action@github.com"
|
||||
git config --local user.name "GitHub Action"
|
||||
BRANCH_NAME="regenerate-examples-${{ github.sha }}"
|
||||
git checkout -b "$BRANCH_NAME"
|
||||
git add examples/
|
||||
git commit -m "chore: regenerate examples"
|
||||
git push origin "$BRANCH_NAME"
|
||||
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
|
||||
id: create-branch
|
||||
|
||||
- name: Create Pull Request
|
||||
if: steps.verify-changed-files.outputs.changed == 'true'
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
gh pr create \
|
||||
--title "chore: regenerate examples" \
|
||||
--body "Automated regeneration of examples from the main branch." \
|
||||
--head "${{ steps.create-branch.outputs.branch_name }}" \
|
||||
--base main
|
||||
echo "pr_number=$(gh pr list --head ${{ steps.create-branch.outputs.branch_name }} --json number --jq '.[0].number')" >> $GITHUB_OUTPUT
|
||||
id: create-pr
|
||||
|
||||
- name: Auto-approve and merge Pull Request
|
||||
if: steps.verify-changed-files.outputs.changed == 'true'
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
gh pr review "${{ steps.create-branch.outputs.branch_name }}" --approve
|
||||
gh pr merge "${{ steps.create-branch.outputs.branch_name }}" --squash
|
||||
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@@ -37,10 +37,6 @@ jobs:
|
||||
version: 9.15.4
|
||||
run_install: false
|
||||
|
||||
- name: Install Atlas
|
||||
run: |
|
||||
curl -sSf https://atlasgo.sh | sh
|
||||
|
||||
- name: Compose
|
||||
run: docker compose up -d
|
||||
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -95,3 +95,7 @@ rabbitmq.conf
|
||||
certs/
|
||||
|
||||
openapitools.json
|
||||
|
||||
# Generated docs content
|
||||
frontend/app/src/next/lib/docs/generated/
|
||||
frontend/docs/lib/generated/
|
||||
|
||||
@@ -55,11 +55,7 @@ tasks:
|
||||
EOF
|
||||
pre:
|
||||
cmds:
|
||||
# FIXME: Remove this once we have a better way to handle pre-commit reliably
|
||||
- cd frontend/snips/ && pnpm i && pnpm generate && pnpm run copy:all
|
||||
- cd frontend/app/ && pnpm run lint:fix
|
||||
- pre-commit run --all-files
|
||||
- pre-commit run --all-files
|
||||
- cd frontend/app/ && pnpm run prettier:fix
|
||||
- pre-commit run --all-files
|
||||
start-db:
|
||||
cmds:
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import asyncio
|
||||
import time
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
|
||||
from examples.concurrency_cancel_in_progress.worker import (
|
||||
WorkflowInput,
|
||||
concurrency_cancel_in_progress_workflow,
|
||||
)
|
||||
from hatchet_sdk import Hatchet, TriggerWorkflowOptions, V1TaskStatus, WorkflowRunRef
|
||||
|
||||
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_run(hatchet: Hatchet) -> None:
|
||||
test_run_id = str(uuid4())
|
||||
refs: list[WorkflowRunRef] = []
|
||||
|
||||
for i in range(10):
|
||||
ref = await concurrency_cancel_in_progress_workflow.aio_run_no_wait(
|
||||
WorkflowInput(group="A"),
|
||||
options=TriggerWorkflowOptions(
|
||||
additional_metadata={"test_run_id": test_run_id, "i": str(i)},
|
||||
),
|
||||
)
|
||||
refs.append(ref)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
for ref in refs:
|
||||
print(f"Waiting for run {ref.workflow_run_id} to complete")
|
||||
try:
|
||||
await ref.aio_result()
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
## wait for the olap repo to catch up
|
||||
await asyncio.sleep(5)
|
||||
|
||||
runs = sorted(
|
||||
hatchet.runs.list(additional_metadata={"test_run_id": test_run_id}).rows,
|
||||
key=lambda r: int((r.additional_metadata or {}).get("i", "0")),
|
||||
)
|
||||
|
||||
assert len(runs) == 10
|
||||
assert (runs[-1].additional_metadata or {}).get("i") == "9"
|
||||
assert runs[-1].status == V1TaskStatus.COMPLETED
|
||||
assert all(r.status == V1TaskStatus.CANCELLED for r in runs[:-1])
|
||||
39
examples/python/concurrency_cancel_in_progress/worker.py
Normal file
39
examples/python/concurrency_cancel_in_progress/worker.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import asyncio
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from hatchet_sdk import (
|
||||
ConcurrencyExpression,
|
||||
ConcurrencyLimitStrategy,
|
||||
Context,
|
||||
Hatchet,
|
||||
)
|
||||
|
||||
hatchet = Hatchet(debug=True)
|
||||
|
||||
|
||||
class WorkflowInput(BaseModel):
|
||||
group: str
|
||||
|
||||
|
||||
concurrency_cancel_in_progress_workflow = hatchet.workflow(
|
||||
name="ConcurrencyCancelInProgress",
|
||||
concurrency=ConcurrencyExpression(
|
||||
expression="input.group",
|
||||
max_runs=1,
|
||||
limit_strategy=ConcurrencyLimitStrategy.CANCEL_IN_PROGRESS,
|
||||
),
|
||||
input_validator=WorkflowInput,
|
||||
)
|
||||
|
||||
|
||||
@concurrency_cancel_in_progress_workflow.task()
|
||||
async def step1(input: WorkflowInput, ctx: Context) -> None:
|
||||
for _ in range(50):
|
||||
await asyncio.sleep(0.10)
|
||||
|
||||
|
||||
@concurrency_cancel_in_progress_workflow.task(parents=[step1])
|
||||
async def step2(input: WorkflowInput, ctx: Context) -> None:
|
||||
for _ in range(50):
|
||||
await asyncio.sleep(0.10)
|
||||
@@ -0,0 +1,61 @@
|
||||
import asyncio
|
||||
import time
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
|
||||
from examples.concurrency_cancel_newest.worker import (
|
||||
WorkflowInput,
|
||||
concurrency_cancel_newest_workflow,
|
||||
)
|
||||
from hatchet_sdk import Hatchet, TriggerWorkflowOptions, V1TaskStatus
|
||||
|
||||
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_run(hatchet: Hatchet) -> None:
|
||||
test_run_id = str(uuid4())
|
||||
to_run = await concurrency_cancel_newest_workflow.aio_run_no_wait(
|
||||
WorkflowInput(group="A"),
|
||||
options=TriggerWorkflowOptions(
|
||||
additional_metadata={
|
||||
"test_run_id": test_run_id,
|
||||
},
|
||||
),
|
||||
)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
to_cancel = await concurrency_cancel_newest_workflow.aio_run_many_no_wait(
|
||||
[
|
||||
concurrency_cancel_newest_workflow.create_bulk_run_item(
|
||||
input=WorkflowInput(group="A"),
|
||||
options=TriggerWorkflowOptions(
|
||||
additional_metadata={
|
||||
"test_run_id": test_run_id,
|
||||
},
|
||||
),
|
||||
)
|
||||
for _ in range(10)
|
||||
]
|
||||
)
|
||||
|
||||
await to_run.aio_result()
|
||||
|
||||
for ref in to_cancel:
|
||||
try:
|
||||
await ref.aio_result()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
## wait for the olap repo to catch up
|
||||
await asyncio.sleep(5)
|
||||
|
||||
successful_run = hatchet.runs.get(to_run.workflow_run_id)
|
||||
|
||||
assert successful_run.run.status == V1TaskStatus.COMPLETED
|
||||
assert all(
|
||||
r.status == V1TaskStatus.CANCELLED
|
||||
for r in hatchet.runs.list(
|
||||
additional_metadata={"test_run_id": test_run_id}
|
||||
).rows
|
||||
if r.metadata.id != to_run.workflow_run_id
|
||||
)
|
||||
39
examples/python/concurrency_cancel_newest/worker.py
Normal file
39
examples/python/concurrency_cancel_newest/worker.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import asyncio
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from hatchet_sdk import (
|
||||
ConcurrencyExpression,
|
||||
ConcurrencyLimitStrategy,
|
||||
Context,
|
||||
Hatchet,
|
||||
)
|
||||
|
||||
hatchet = Hatchet(debug=True)
|
||||
|
||||
|
||||
class WorkflowInput(BaseModel):
|
||||
group: str
|
||||
|
||||
|
||||
concurrency_cancel_newest_workflow = hatchet.workflow(
|
||||
name="ConcurrencyCancelNewest",
|
||||
concurrency=ConcurrencyExpression(
|
||||
expression="input.group",
|
||||
max_runs=1,
|
||||
limit_strategy=ConcurrencyLimitStrategy.CANCEL_NEWEST,
|
||||
),
|
||||
input_validator=WorkflowInput,
|
||||
)
|
||||
|
||||
|
||||
@concurrency_cancel_newest_workflow.task()
|
||||
async def step1(input: WorkflowInput, ctx: Context) -> None:
|
||||
for _ in range(50):
|
||||
await asyncio.sleep(0.10)
|
||||
|
||||
|
||||
@concurrency_cancel_newest_workflow.task(parents=[step1])
|
||||
async def step2(input: WorkflowInput, ctx: Context) -> None:
|
||||
for _ in range(50):
|
||||
await asyncio.sleep(0.10)
|
||||
@@ -35,7 +35,7 @@ async def step3(input: EmptyModel, ctx: Context) -> RandomSum:
|
||||
one = ctx.task_output(step1).random_number
|
||||
two = ctx.task_output(step2).random_number
|
||||
|
||||
return RandomSum(sum=one + two)
|
||||
return RandomSum(sum=one + two + 3)
|
||||
|
||||
|
||||
@dag_workflow.task(parents=[step1, step3])
|
||||
|
||||
@@ -6,6 +6,10 @@ from examples.bulk_operations.worker import (
|
||||
bulk_replay_test_3,
|
||||
)
|
||||
from examples.cancellation.worker import cancellation_workflow
|
||||
from examples.concurrency_cancel_in_progress.worker import (
|
||||
concurrency_cancel_in_progress_workflow,
|
||||
)
|
||||
from examples.concurrency_cancel_newest.worker import concurrency_cancel_newest_workflow
|
||||
from examples.concurrency_limit.worker import concurrency_limit_workflow
|
||||
from examples.concurrency_limit_rr.worker import concurrency_limit_rr_workflow
|
||||
from examples.concurrency_multiple_keys.worker import concurrency_multiple_keys_workflow
|
||||
@@ -68,6 +72,8 @@ def main() -> None:
|
||||
sync_fanout_child,
|
||||
non_retryable_workflow,
|
||||
concurrency_workflow_level_workflow,
|
||||
concurrency_cancel_newest_workflow,
|
||||
concurrency_cancel_in_progress_workflow,
|
||||
di_workflow,
|
||||
lifespan_task,
|
||||
simple,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"type": "module",
|
||||
"packageManager": "pnpm@9.15.4",
|
||||
"scripts": {
|
||||
"dev": "npm run sync-docs && npm run sync-examples && npm run prettier:fix && vite",
|
||||
"dev": "vite",
|
||||
"build": "tsc && vite build",
|
||||
"lint:check": "npm run eslint:check && npm run prettier:check",
|
||||
"lint:fix": "npm run eslint:fix && npm run prettier:fix",
|
||||
@@ -14,8 +14,7 @@
|
||||
"prettier:check": "prettier \"src/**/*.{ts,tsx}\" --list-different",
|
||||
"prettier:fix": "prettier \"src/**/*.{ts,tsx}\" --write",
|
||||
"preview": "vite preview",
|
||||
"sync-docs": "tsx src/next/lib/docs/sync-docs.ts && eslint \"src/next/lib/docs/generated/**/*.{ts,tsx,js}\" --fix --cache && prettier \"src/next/lib/docs/generated/**/*.{ts,tsx}\" --write",
|
||||
"sync-examples": "cd ../snips/ && pnpm i && pnpm generate && pnpm run copy:app"
|
||||
"sync-examples": "cd ../snips/ && pnpm i && pnpm generate"
|
||||
},
|
||||
"dependencies": {
|
||||
"@heroicons/react": "^2.2.0",
|
||||
|
||||
3114
frontend/app/pnpm-lock.yaml
generated
3114
frontend/app/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -53,6 +53,7 @@ export interface ApiConfig<SecurityDataType = unknown>
|
||||
|
||||
export enum ContentType {
|
||||
Json = "application/json",
|
||||
JsonApi = "application/vnd.api+json",
|
||||
FormData = "multipart/form-data",
|
||||
UrlEncoded = "application/x-www-form-urlencoded",
|
||||
Text = "text/plain",
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
// Generated from frontend/docs/pages/_meta.js
|
||||
const meta = {
|
||||
home: {
|
||||
title: 'User Guide',
|
||||
type: 'page',
|
||||
theme: {
|
||||
toc: false,
|
||||
},
|
||||
},
|
||||
_setup: {
|
||||
display: 'hidden',
|
||||
},
|
||||
compute: {
|
||||
title: 'Managed Compute',
|
||||
type: 'page',
|
||||
href: '/home/compute',
|
||||
index: 'Overview',
|
||||
'getting-started': 'Getting Started',
|
||||
cpu: 'CPU Machine Types',
|
||||
gpu: 'GPU Machine Types',
|
||||
},
|
||||
self_hosting: {
|
||||
title: 'Self Hosting',
|
||||
type: 'page',
|
||||
theme: {
|
||||
toc: false,
|
||||
},
|
||||
},
|
||||
blog: {
|
||||
title: 'Blog',
|
||||
type: 'page',
|
||||
},
|
||||
contributing: {
|
||||
title: 'Contributing',
|
||||
type: 'page',
|
||||
display: 'hidden',
|
||||
theme: {
|
||||
toc: false,
|
||||
},
|
||||
},
|
||||
sdks: {
|
||||
title: 'SDK Reference',
|
||||
type: 'menu',
|
||||
items: {
|
||||
python: {
|
||||
title: 'Python',
|
||||
href: '/sdks/python/client',
|
||||
type: 'page',
|
||||
},
|
||||
},
|
||||
},
|
||||
v0: {
|
||||
title: 'V0 (Old docs)',
|
||||
type: 'page',
|
||||
href: 'https://v0-docs.hatchet.run',
|
||||
},
|
||||
};
|
||||
export default meta;
|
||||
@@ -1,49 +0,0 @@
|
||||
// Generated from frontend/docs/pages/blog/_meta.js
|
||||
const meta = {
|
||||
background_tasks_fastapi_hatchet: {
|
||||
title: 'Background Tasks: From FastAPI to Hatchet',
|
||||
href: '/blog/background-tasks-fastapi-hatchet',
|
||||
},
|
||||
go_agents: {
|
||||
title: 'Why Go is a good fit for agents',
|
||||
href: '/blog/go-agents',
|
||||
},
|
||||
warning_event_loop_blocked: {
|
||||
title: 'Warning! The Event Loop May Be Blocked',
|
||||
href: '/blog/warning-event-loop-blocked',
|
||||
},
|
||||
fastest_postgres_inserts: {
|
||||
title: 'The fastest Postgres inserts',
|
||||
href: '/blog/fastest-postgres-inserts',
|
||||
},
|
||||
task_queue_modern_python: {
|
||||
title: 'A task queue for modern Python applications',
|
||||
href: '/blog/task-queue-modern-python',
|
||||
},
|
||||
postgres_events_table: {
|
||||
title: 'Use Postgres for your events table',
|
||||
href: '/blog/postgres-events-table',
|
||||
},
|
||||
migrating_off_prisma: {
|
||||
title: 'Why we moved off Prisma',
|
||||
href: '/blog/migrating-off-prisma',
|
||||
},
|
||||
problems_with_celery: {
|
||||
title: 'The problems with Celery',
|
||||
display: 'hidden',
|
||||
href: '/blog/problems-with-celery',
|
||||
},
|
||||
multi_tenant_queues: {
|
||||
title: 'An unfair advantage: multi-tenant queues in Postgres',
|
||||
href: '/blog/multi-tenant-queues',
|
||||
},
|
||||
'--migration-guides': {
|
||||
title: 'Migration Guides',
|
||||
type: 'separator',
|
||||
},
|
||||
mergent_migration_guide: {
|
||||
title: 'Migrating from Mergent',
|
||||
href: '/blog/mergent-migration-guide',
|
||||
},
|
||||
};
|
||||
export default meta;
|
||||
@@ -1,16 +0,0 @@
|
||||
// Generated from frontend/docs/pages/contributing/_meta.js
|
||||
const meta = {
|
||||
index: {
|
||||
title: 'Contributing',
|
||||
href: '/contributing/',
|
||||
},
|
||||
github_app_setup: {
|
||||
title: 'GitHub App Setup',
|
||||
href: '/contributing/github-app-setup',
|
||||
},
|
||||
sdks: {
|
||||
title: 'SDKs',
|
||||
href: '/contributing/sdks',
|
||||
},
|
||||
};
|
||||
export default meta;
|
||||
@@ -1,265 +0,0 @@
|
||||
// Generated from frontend/docs/pages/home/_meta.js
|
||||
const meta = {
|
||||
'--intro': {
|
||||
title: 'Introduction',
|
||||
type: 'separator',
|
||||
},
|
||||
index: {
|
||||
title: 'Introduction',
|
||||
href: '/home/',
|
||||
},
|
||||
hatchet_cloud_quickstart: {
|
||||
title: 'Hatchet Cloud Quickstart',
|
||||
href: '/home/hatchet-cloud-quickstart',
|
||||
},
|
||||
'--quickstart': {
|
||||
title: 'Quickstart',
|
||||
type: 'separator',
|
||||
},
|
||||
setup: {
|
||||
title: 'Setup',
|
||||
href: '/home/setup',
|
||||
},
|
||||
your_first_task: {
|
||||
title: 'Tasks',
|
||||
href: '/home/your-first-task',
|
||||
},
|
||||
workers: {
|
||||
title: 'Workers',
|
||||
href: '/home/workers',
|
||||
},
|
||||
running_your_task: {
|
||||
title: 'Running Tasks',
|
||||
href: '/home/running-your-task',
|
||||
},
|
||||
environments: {
|
||||
title: 'Environments',
|
||||
href: '/home/environments',
|
||||
},
|
||||
'--running-tasks': {
|
||||
title: 'Ways of Running Tasks',
|
||||
type: 'separator',
|
||||
},
|
||||
running_tasks: {
|
||||
title: 'Introduction',
|
||||
href: '/home/running-tasks',
|
||||
},
|
||||
run_with_results: {
|
||||
title: 'Run and Wait Trigger',
|
||||
href: '/home/run-with-results',
|
||||
},
|
||||
run_no_wait: {
|
||||
title: 'Run Without Wait Trigger',
|
||||
href: '/home/run-no-wait',
|
||||
},
|
||||
scheduled_runs: {
|
||||
title: 'Scheduled Trigger',
|
||||
href: '/home/scheduled-runs',
|
||||
},
|
||||
cron_runs: {
|
||||
title: 'Cron Trigger',
|
||||
href: '/home/cron-runs',
|
||||
},
|
||||
run_on_event: {
|
||||
title: 'Event Trigger',
|
||||
href: '/home/run-on-event',
|
||||
},
|
||||
bulk_run: {
|
||||
title: 'Bulk Run Many',
|
||||
href: '/home/bulk-run',
|
||||
},
|
||||
webhooks: {
|
||||
title: 'Webhooks',
|
||||
href: '/home/webhooks',
|
||||
},
|
||||
'--flow-control': {
|
||||
title: 'Flow Control',
|
||||
type: 'separator',
|
||||
},
|
||||
concurrency: {
|
||||
title: 'Concurrency',
|
||||
href: '/home/concurrency',
|
||||
},
|
||||
rate_limits: {
|
||||
title: 'Rate Limits',
|
||||
href: '/home/rate-limits',
|
||||
},
|
||||
priority: {
|
||||
title: 'Priority',
|
||||
href: '/home/priority',
|
||||
},
|
||||
'--advanced-workflows': {
|
||||
title: 'Workflows',
|
||||
type: 'separator',
|
||||
},
|
||||
orchestration: {
|
||||
title: 'Task Orchestration',
|
||||
href: '/home/orchestration',
|
||||
},
|
||||
dags: {
|
||||
title: 'Directed Acyclic Graphs (DAGs)',
|
||||
href: '/home/dags',
|
||||
},
|
||||
conditional_workflows: {
|
||||
title: 'Conditional Workflows',
|
||||
href: '/home/conditional-workflows',
|
||||
},
|
||||
on_failure_tasks: {
|
||||
title: 'On Failure Tasks',
|
||||
href: '/home/on-failure-tasks',
|
||||
},
|
||||
child_spawning: {
|
||||
title: 'Child Spawning',
|
||||
href: '/home/child-spawning',
|
||||
},
|
||||
additional_metadata: {
|
||||
title: 'Additional Metadata',
|
||||
href: '/home/additional-metadata',
|
||||
},
|
||||
'--durable-execution': {
|
||||
title: 'Durable Execution',
|
||||
type: 'separator',
|
||||
},
|
||||
durable_execution: {
|
||||
title: 'Durable Execution',
|
||||
href: '/home/durable-execution',
|
||||
},
|
||||
durable_events: {
|
||||
title: 'Durable Events',
|
||||
href: '/home/durable-events',
|
||||
},
|
||||
durable_sleep: {
|
||||
title: 'Durable Sleep',
|
||||
href: '/home/durable-sleep',
|
||||
},
|
||||
durable_best_practices: {
|
||||
title: 'Best Practices',
|
||||
href: '/home/durable-best-practices',
|
||||
},
|
||||
'--error-handling': {
|
||||
title: 'Error Handling',
|
||||
type: 'separator',
|
||||
},
|
||||
timeouts: {
|
||||
title: 'Timeouts',
|
||||
href: '/home/timeouts',
|
||||
},
|
||||
retry_policies: {
|
||||
title: 'Retry Policies',
|
||||
href: '/home/retry-policies',
|
||||
},
|
||||
bulk_retries_and_cancellations: {
|
||||
title: 'Bulk Retries and Cancellations',
|
||||
href: '/home/bulk-retries-and-cancellations',
|
||||
},
|
||||
'--assignment': {
|
||||
title: 'Advanced Assignment',
|
||||
type: 'separator',
|
||||
},
|
||||
sticky_assignment: {
|
||||
title: 'Sticky Assignment',
|
||||
href: '/home/sticky-assignment',
|
||||
},
|
||||
worker_affinity: {
|
||||
title: 'Worker Affinity',
|
||||
href: '/home/worker-affinity',
|
||||
},
|
||||
manual_slot_release: {
|
||||
title: 'Manual Slot Release',
|
||||
href: '/home/manual-slot-release',
|
||||
},
|
||||
'--observability': {
|
||||
title: 'Observability',
|
||||
type: 'separator',
|
||||
},
|
||||
logging: {
|
||||
title: 'Logging',
|
||||
href: '/home/logging',
|
||||
},
|
||||
opentelemetry: {
|
||||
title: 'OpenTelemetry',
|
||||
href: '/home/opentelemetry',
|
||||
},
|
||||
prometheus_metrics: {
|
||||
title: 'Prometheus Metrics',
|
||||
href: '/home/prometheus-metrics',
|
||||
},
|
||||
'--deploying-workers': {
|
||||
title: 'Deploying Workers',
|
||||
type: 'separator',
|
||||
},
|
||||
docker: {
|
||||
title: 'Running with Docker',
|
||||
href: '/home/docker',
|
||||
},
|
||||
compute: {
|
||||
title: 'Managed Compute',
|
||||
href: '/home/compute',
|
||||
},
|
||||
worker_healthchecks: {
|
||||
title: 'Worker Health Checks',
|
||||
href: '/home/worker-healthchecks',
|
||||
},
|
||||
'--advanced-tasks': {
|
||||
title: 'Advanced Task Features',
|
||||
type: 'separator',
|
||||
},
|
||||
cancellation: {
|
||||
title: 'Cancellation',
|
||||
href: '/home/cancellation',
|
||||
},
|
||||
streaming: {
|
||||
title: 'Streaming',
|
||||
href: '/home/streaming',
|
||||
},
|
||||
'--v1-migration-guides': {
|
||||
title: 'V1 Migration Guides',
|
||||
type: 'separator',
|
||||
},
|
||||
v1_sdk_improvements: {
|
||||
title: 'SDK Improvements',
|
||||
href: '/home/v1-sdk-improvements',
|
||||
},
|
||||
migration_guide_engine: {
|
||||
title: 'Engine Migration Guide',
|
||||
href: '/home/migration-guide-engine',
|
||||
},
|
||||
migration_guide_python: {
|
||||
title: 'Python Migration Guide',
|
||||
href: '/home/migration-guide-python',
|
||||
},
|
||||
migration_guide_typescript: {
|
||||
title: 'Typescript Migration Guide',
|
||||
href: '/home/migration-guide-typescript',
|
||||
},
|
||||
migration_guide_go: {
|
||||
title: 'Go Migration Guide',
|
||||
href: '/home/migration-guide-go',
|
||||
},
|
||||
'--python': {
|
||||
title: 'Python Specifics',
|
||||
type: 'separator',
|
||||
},
|
||||
asyncio: {
|
||||
title: 'Asyncio',
|
||||
href: '/home/asyncio',
|
||||
},
|
||||
pydantic: {
|
||||
title: 'Pydantic',
|
||||
href: '/home/pydantic',
|
||||
},
|
||||
lifespans: {
|
||||
title: 'Lifespans',
|
||||
href: '/home/lifespans',
|
||||
},
|
||||
dependency_injection: {
|
||||
title: 'Dependency Injection',
|
||||
href: '/home/dependency-injection',
|
||||
},
|
||||
blog: {
|
||||
title: 'Blog',
|
||||
type: 'page',
|
||||
href: '/blog',
|
||||
},
|
||||
};
|
||||
export default meta;
|
||||
@@ -1,32 +0,0 @@
|
||||
// Generated from frontend/docs/pages/home/compute/_meta.js
|
||||
const meta = {
|
||||
index: {
|
||||
title: 'Overview',
|
||||
href: '/home/compute/',
|
||||
},
|
||||
getting_started: {
|
||||
title: 'Getting Started',
|
||||
href: '/home/compute/getting-started',
|
||||
},
|
||||
cpu: {
|
||||
title: 'CPU Machine Types',
|
||||
href: '/home/compute/cpu',
|
||||
},
|
||||
gpu: {
|
||||
title: 'GPU Machine Types',
|
||||
href: '/home/compute/gpu',
|
||||
},
|
||||
git_ops: {
|
||||
title: 'GitOps',
|
||||
href: '/home/compute/git-ops',
|
||||
},
|
||||
auto_scaling: {
|
||||
title: 'Auto Scaling',
|
||||
href: '/home/compute/auto-scaling',
|
||||
},
|
||||
environment_variables: {
|
||||
title: 'Environment Variables',
|
||||
href: '/home/compute/environment-variables',
|
||||
},
|
||||
};
|
||||
export default meta;
|
||||
@@ -1,21 +0,0 @@
|
||||
// Generated index file for meta-data
|
||||
import root from './_meta';
|
||||
import blog from './blog/_meta';
|
||||
import contributing from './contributing/_meta';
|
||||
import home from './home/_meta';
|
||||
import homecompute from './home/compute/_meta';
|
||||
import sdks from './sdks/_meta';
|
||||
import sdkspython from './sdks/python/_meta';
|
||||
import sdkspythonfeature_clients from './sdks/python/feature-clients/_meta';
|
||||
import self_hosting from './self-hosting/_meta';
|
||||
export {
|
||||
root,
|
||||
blog,
|
||||
contributing,
|
||||
home,
|
||||
homecompute,
|
||||
sdks,
|
||||
sdkspython,
|
||||
sdkspythonfeature_clients,
|
||||
self_hosting,
|
||||
};
|
||||
@@ -1,11 +0,0 @@
|
||||
// Generated from frontend/docs/pages/sdks/_meta.js
|
||||
const meta = {
|
||||
python: {
|
||||
title: 'Python SDK',
|
||||
type: 'page',
|
||||
theme: {
|
||||
toc: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
export default meta;
|
||||
@@ -1,32 +0,0 @@
|
||||
// Generated from frontend/docs/pages/sdks/python/_meta.js
|
||||
const meta = {
|
||||
client: {
|
||||
title: 'Client',
|
||||
theme: {
|
||||
toc: true,
|
||||
},
|
||||
href: '/sdks/python/client',
|
||||
},
|
||||
context: {
|
||||
title: 'Context',
|
||||
theme: {
|
||||
toc: true,
|
||||
},
|
||||
href: '/sdks/python/context',
|
||||
},
|
||||
feature_clients: {
|
||||
title: 'Feature Clients',
|
||||
theme: {
|
||||
toc: true,
|
||||
},
|
||||
href: '/sdks/python/feature-clients',
|
||||
},
|
||||
runnables: {
|
||||
title: 'Runnables',
|
||||
theme: {
|
||||
toc: true,
|
||||
},
|
||||
href: '/sdks/python/runnables',
|
||||
},
|
||||
};
|
||||
export default meta;
|
||||
@@ -1,67 +0,0 @@
|
||||
// Generated from frontend/docs/pages/sdks/python/feature-clients/_meta.js
|
||||
const meta = {
|
||||
cron: {
|
||||
title: 'Cron',
|
||||
theme: {
|
||||
toc: true,
|
||||
},
|
||||
href: '/sdks/python/feature-clients/cron',
|
||||
},
|
||||
filters: {
|
||||
title: 'Filters',
|
||||
theme: {
|
||||
toc: true,
|
||||
},
|
||||
href: '/sdks/python/feature-clients/filters',
|
||||
},
|
||||
logs: {
|
||||
title: 'Logs',
|
||||
theme: {
|
||||
toc: true,
|
||||
},
|
||||
href: '/sdks/python/feature-clients/logs',
|
||||
},
|
||||
metrics: {
|
||||
title: 'Metrics',
|
||||
theme: {
|
||||
toc: true,
|
||||
},
|
||||
href: '/sdks/python/feature-clients/metrics',
|
||||
},
|
||||
rate_limits: {
|
||||
title: 'Rate Limits',
|
||||
theme: {
|
||||
toc: true,
|
||||
},
|
||||
href: '/sdks/python/feature-clients/rate_limits',
|
||||
},
|
||||
runs: {
|
||||
title: 'Runs',
|
||||
theme: {
|
||||
toc: true,
|
||||
},
|
||||
href: '/sdks/python/feature-clients/runs',
|
||||
},
|
||||
scheduled: {
|
||||
title: 'Scheduled',
|
||||
theme: {
|
||||
toc: true,
|
||||
},
|
||||
href: '/sdks/python/feature-clients/scheduled',
|
||||
},
|
||||
workers: {
|
||||
title: 'Workers',
|
||||
theme: {
|
||||
toc: true,
|
||||
},
|
||||
href: '/sdks/python/feature-clients/workers',
|
||||
},
|
||||
workflows: {
|
||||
title: 'Workflows',
|
||||
theme: {
|
||||
toc: true,
|
||||
},
|
||||
href: '/sdks/python/feature-clients/workflows',
|
||||
},
|
||||
};
|
||||
export default meta;
|
||||
@@ -1,87 +0,0 @@
|
||||
// Generated from frontend/docs/pages/self-hosting/_meta.js
|
||||
const meta = {
|
||||
index: {
|
||||
title: 'Introduction',
|
||||
href: '/self-hosting/',
|
||||
},
|
||||
'-- Docker': {
|
||||
type: 'separator',
|
||||
title: 'Docker',
|
||||
},
|
||||
hatchet_lite: {
|
||||
title: 'Hatchet Lite',
|
||||
href: '/self-hosting/hatchet-lite',
|
||||
},
|
||||
docker_compose: {
|
||||
title: 'Docker Compose',
|
||||
href: '/self-hosting/docker-compose',
|
||||
},
|
||||
'-- Kubernetes': {
|
||||
type: 'separator',
|
||||
title: 'Kubernetes',
|
||||
},
|
||||
kubernetes_quickstart: {
|
||||
title: 'Quickstart',
|
||||
href: '/self-hosting/kubernetes-quickstart',
|
||||
},
|
||||
kubernetes_glasskube: {
|
||||
title: 'Installing with Glasskube',
|
||||
href: '/self-hosting/kubernetes-glasskube',
|
||||
},
|
||||
networking: {
|
||||
title: 'Networking',
|
||||
href: '/self-hosting/networking',
|
||||
},
|
||||
kubernetes_helm_configuration: {
|
||||
title: 'Configuring the Helm Chart',
|
||||
href: '/self-hosting/kubernetes-helm-configuration',
|
||||
},
|
||||
kubernetes_external_database: {
|
||||
title: 'Setting up an External Database',
|
||||
href: '/self-hosting/kubernetes-external-database',
|
||||
},
|
||||
high_availability: {
|
||||
title: 'High Availability',
|
||||
href: '/self-hosting/high-availability',
|
||||
},
|
||||
'-- Managing Hatchet': {
|
||||
type: 'separator',
|
||||
title: 'Managing Hatchet',
|
||||
},
|
||||
configuration_options: {
|
||||
title: 'Engine Configuration Options',
|
||||
href: '/self-hosting/configuration-options',
|
||||
},
|
||||
prometheus_metrics: {
|
||||
title: 'Prometheus Metrics',
|
||||
theme: {
|
||||
toc: true,
|
||||
},
|
||||
href: '/self-hosting/prometheus-metrics',
|
||||
},
|
||||
worker_configuration_options: {
|
||||
title: 'Worker Configuration Options',
|
||||
href: '/self-hosting/worker-configuration-options',
|
||||
},
|
||||
benchmarking: {
|
||||
title: 'Benchmarking',
|
||||
href: '/self-hosting/benchmarking',
|
||||
},
|
||||
data_retention: {
|
||||
title: 'Data Retention',
|
||||
href: '/self-hosting/data-retention',
|
||||
},
|
||||
improving_performance: {
|
||||
title: 'Improving Performance',
|
||||
href: '/self-hosting/improving-performance',
|
||||
},
|
||||
read_replicas: {
|
||||
title: 'Read Replicas',
|
||||
href: '/self-hosting/read-replicas',
|
||||
},
|
||||
sampling: {
|
||||
title: 'Trace Sampling',
|
||||
href: '/self-hosting/sampling',
|
||||
},
|
||||
};
|
||||
export default meta;
|
||||
@@ -1,3 +0,0 @@
|
||||
import main from './main';
|
||||
|
||||
export { main };
|
||||
@@ -1,29 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"context"\n\t"fmt"\n\t"log"\n\t"time"\n\n\t"github.com/google/uuid"\n\t"github.com/oapi-codegen/runtime/types"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client/rest"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n)\n\nfunc main() {\n\t// > Setup\n\n\thatchet, err := v1.NewHatchetClient()\n\tif err != nil {\n\t\tlog.Fatalf("failed to create hatchet client: %v", err)\n\t}\n\n\tctx := context.Background()\n\n\tworkflows, err := hatchet.Workflows().List(ctx, nil)\n\tif err != nil {\n\t\tlog.Fatalf("failed to list workflows: %v", err)\n\t}\n\n\tif workflows == nil || workflows.Rows == nil || len(*workflows.Rows) == 0 {\n\t\tlog.Fatalf("no workflows found")\n\t}\n\n\tselectedWorkflow := (*workflows.Rows)[0]\n\tselectedWorkflowUUID := uuid.MustParse(selectedWorkflow.Metadata.Id)\n\n\n\t// > List runs\n\tworkflowRuns, err := hatchet.Runs().List(ctx, rest.V1WorkflowRunListParams{\n\t\tWorkflowIds: &[]types.UUID{selectedWorkflowUUID},\n\t})\n\tif err != nil || workflowRuns == nil || workflowRuns.JSON200 == nil || workflowRuns.JSON200.Rows == nil {\n\t\tlog.Fatalf("failed to list workflow runs for workflow %s: %v", selectedWorkflow.Name, err)\n\t}\n\n\tvar runIds []types.UUID\n\n\tfor _, run := range workflowRuns.JSON200.Rows {\n\t\trunIds = append(runIds, uuid.MustParse(run.Metadata.Id))\n\t}\n\n\n\t// > Cancel by run ids\n\t_, err = hatchet.Runs().Cancel(ctx, rest.V1CancelTaskRequest{\n\t\tExternalIds: &runIds,\n\t})\n\tif err != nil {\n\t\tlog.Fatalf("failed to cancel runs by ids: %v", err)\n\t}\n\n\n\t// > Cancel by filters\n\ttNow := time.Now().UTC()\n\n\t_, err = hatchet.Runs().Cancel(ctx, rest.V1CancelTaskRequest{\n\t\tFilter: &rest.V1TaskFilter{\n\t\t\tSince: tNow.Add(-24 * time.Hour),\n\t\t\tUntil: &tNow,\n\t\t\tStatuses: &[]rest.V1TaskStatus{rest.V1TaskStatusRUNNING},\n\t\t\tWorkflowIds: &[]types.UUID{selectedWorkflowUUID},\n\t\t\tAdditionalMetadata: &[]string{`{"key": "value"}`},\n\t\t},\n\t})\n\tif err != nil {\n\t\tlog.Fatalf("failed to cancel runs by filters: %v", err)\n\t}\n\n\n\tfmt.Println("cancelled all runs for workflow", selectedWorkflow.Name)\n}\n',
|
||||
source: 'out/go/bulk-operations/main.go',
|
||||
blocks: {
|
||||
setup: {
|
||||
start: 18,
|
||||
stop: 37,
|
||||
},
|
||||
list_runs: {
|
||||
start: 40,
|
||||
stop: 52,
|
||||
},
|
||||
cancel_by_run_ids: {
|
||||
start: 55,
|
||||
stop: 61,
|
||||
},
|
||||
cancel_by_filters: {
|
||||
start: 64,
|
||||
stop: 78,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,17 +0,0 @@
|
||||
import * as bulk_operations from './bulk-operations';
|
||||
import * as migration_guides from './migration-guides';
|
||||
import * as quickstart from './quickstart';
|
||||
import * as run from './run';
|
||||
import * as streaming from './streaming';
|
||||
import * as worker from './worker';
|
||||
import * as workflows from './workflows';
|
||||
import * as z_v0 from './z_v0';
|
||||
|
||||
export { bulk_operations };
|
||||
export { migration_guides };
|
||||
export { quickstart };
|
||||
export { run };
|
||||
export { streaming };
|
||||
export { worker };
|
||||
export { workflows };
|
||||
export { z_v0 };
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package migration_guides\n\nimport (\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n)\n\nfunc HatchetClient() (v1.HatchetClient, error) {\n\thatchet, err := v1.NewHatchetClient()\n\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn hatchet, nil\n}\n',
|
||||
source: 'out/go/migration-guides/hatchet-client.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,5 +0,0 @@
|
||||
import hatchet_client from './hatchet-client';
|
||||
import mergent from './mergent';
|
||||
|
||||
export { hatchet_client };
|
||||
export { mergent };
|
||||
File diff suppressed because one or more lines are too long
@@ -1,5 +0,0 @@
|
||||
import * as run from './run';
|
||||
import * as worker from './worker';
|
||||
|
||||
export { run };
|
||||
export { worker };
|
||||
@@ -1,3 +0,0 @@
|
||||
import main from './main';
|
||||
|
||||
export { main };
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\thatchet_client "github.com/hatchet-dev/hatchet/pkg/examples/quickstart/hatchet_client"\n\tworkflows "github.com/hatchet-dev/hatchet/pkg/examples/quickstart/workflows"\n)\n\nfunc main() {\n\thatchet, err := hatchet_client.HatchetClient()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tsimple := workflows.FirstTask(hatchet)\n\n\tresult, err := simple.Run(context.Background(), workflows.SimpleInput{\n\t\tMessage: "Hello, World!",\n\t})\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(\n\t\t"Finished running task, and got the transformed message! The transformed message is:",\n\t\tresult.ToLower.TransformedMessage,\n\t)\n}\n',
|
||||
source: 'out/go/quickstart/cmd/run/main.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,3 +0,0 @@
|
||||
import main from './main';
|
||||
|
||||
export { main };
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\thatchet_client "github.com/hatchet-dev/hatchet/pkg/examples/quickstart/hatchet_client"\n\tworkflows "github.com/hatchet-dev/hatchet/pkg/examples/quickstart/workflows"\n\n\t"github.com/hatchet-dev/hatchet/pkg/cmdutils"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/worker"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n)\n\nfunc main() {\n\n\thatchet, err := hatchet_client.HatchetClient()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tworker, err := hatchet.Worker(\n\t\tworker.WorkerOpts{\n\t\t\tName: "first-worker",\n\t\t\tWorkflows: []workflow.WorkflowBase{\n\t\t\t\tworkflows.FirstTask(hatchet),\n\t\t\t},\n\t\t},\n\t)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// we construct an interrupt context to handle Ctrl+C\n\t// you can pass in your own context.Context here to the worker\n\tinterruptCtx, cancel := cmdutils.NewInterruptContext()\n\n\tdefer cancel()\n\n\terr = worker.StartBlocking(interruptCtx)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n',
|
||||
source: 'out/go/quickstart/cmd/worker/main.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package hatchet_client\n\nimport (\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/joho/godotenv"\n)\n\nfunc HatchetClient() (v1.HatchetClient, error) {\n\terr := godotenv.Load()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn v1.NewHatchetClient()\n}\n',
|
||||
source: 'out/go/quickstart/hatchet_client/hatchet_client.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,3 +0,0 @@
|
||||
import hatchet_client from './hatchet_client';
|
||||
|
||||
export { hatchet_client };
|
||||
@@ -1,7 +0,0 @@
|
||||
import * as cmd from './cmd';
|
||||
import * as hatchet_client from './hatchet_client';
|
||||
import * as workflows from './workflows';
|
||||
|
||||
export { cmd };
|
||||
export { hatchet_client };
|
||||
export { workflows };
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package workflows\n\nimport (\n\t"fmt"\n\t"strings"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client/create"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/factory"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype SimpleInput struct {\n\tMessage string `json:"message"`\n}\n\ntype LowerOutput struct {\n\tTransformedMessage string `json:"transformed_message"`\n}\n\ntype SimpleResult struct {\n\tToLower LowerOutput\n}\n\nfunc FirstTask(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[SimpleInput, SimpleResult] {\n\tsimple := factory.NewWorkflow[SimpleInput, SimpleResult](\n\t\tcreate.WorkflowCreateOpts[SimpleInput]{\n\t\t\tName: "first-task",\n\t\t},\n\t\thatchet,\n\t)\n\n\tsimple.Task(\n\t\tcreate.WorkflowTask[SimpleInput, SimpleResult]{\n\t\t\tName: "first-task",\n\t\t},\n\t\tfunc(ctx worker.HatchetContext, input SimpleInput) (any, error) {\n\t\t\tfmt.Println("first-task task called")\n\t\t\treturn &LowerOutput{\n\t\t\t\tTransformedMessage: strings.ToLower(input.Message),\n\t\t\t}, nil\n\t\t},\n\t)\n\n\treturn simple\n}\n',
|
||||
source: 'out/go/quickstart/workflows/first_task.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,3 +0,0 @@
|
||||
import first_task from './first_task';
|
||||
|
||||
export { first_task };
|
||||
File diff suppressed because one or more lines are too long
@@ -1,17 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\tv1_workflows "github.com/hatchet-dev/hatchet/examples/go/workflows"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/joho/godotenv"\n)\n\nfunc bulk() {\n\terr := godotenv.Load()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\thatchet, err := v1.NewHatchetClient()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tctx := context.Background()\n\t// > Bulk Run Tasks\n\tsimple := v1_workflows.Simple(hatchet)\n\tbulkRunIds, err := simple.RunBulkNoWait(ctx, []v1_workflows.SimpleInput{\n\t\t{\n\t\t\tMessage: "Hello, World!",\n\t\t},\n\t\t{\n\t\t\tMessage: "Hello, Moon!",\n\t\t},\n\t})\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(bulkRunIds)\n}\n',
|
||||
source: 'out/go/run/bulk.go',
|
||||
blocks: {
|
||||
bulk_run_tasks: {
|
||||
start: 26,
|
||||
stop: 40,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,25 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\tv1_workflows "github.com/hatchet-dev/hatchet/examples/go/workflows"\n\t"github.com/hatchet-dev/hatchet/pkg/client/rest"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/joho/godotenv"\n)\n\nfunc cron() {\n\terr := godotenv.Load()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\thatchet, err := v1.NewHatchetClient()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t// > Create\n\tsimple := v1_workflows.Simple(hatchet)\n\n\tctx := context.Background()\n\n\tresult, err := simple.Cron(\n\t\tctx,\n\t\t"daily-run",\n\t\t"0 0 * * *",\n\t\tv1_workflows.SimpleInput{\n\t\t\tMessage: "Hello, World!",\n\t\t},\n\t)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// it may be useful to save the cron id for later\n\tfmt.Println(result.Metadata.Id)\n\n\t// > Delete\n\thatchet.Crons().Delete(ctx, result.Metadata.Id)\n\n\t// > List\n\tcrons, err := hatchet.Crons().List(ctx, rest.CronWorkflowListParams{\n\t\tAdditionalMetadata: &[]string{"user:daily-run"},\n\t})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(crons)\n}\n',
|
||||
source: 'out/go/run/cron.go',
|
||||
blocks: {
|
||||
create: {
|
||||
start: 25,
|
||||
stop: 43,
|
||||
},
|
||||
delete: {
|
||||
start: 46,
|
||||
stop: 46,
|
||||
},
|
||||
list: {
|
||||
start: 49,
|
||||
stop: 51,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,29 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"context"\n\n\t"github.com/google/uuid"\n\t"github.com/joho/godotenv"\n\n\tv1_workflows "github.com/hatchet-dev/hatchet/examples/go/workflows"\n\t"github.com/hatchet-dev/hatchet/pkg/client"\n\t"github.com/hatchet-dev/hatchet/pkg/client/rest"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n)\n\nfunc event() {\n\terr := godotenv.Load()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\thatchet, err := v1.NewHatchetClient()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t// > Pushing an Event\n\terr = hatchet.Events().Push(\n\t\tcontext.Background(),\n\t\t"simple-event:create",\n\t\tv1_workflows.SimpleInput{\n\t\t\tMessage: "Hello, World!",\n\t\t},\n\t)\n\n\t// > Create a filter\n\tpayload := map[string]interface{}{\n\t\t"main_character": "Anna",\n\t\t"supporting_character": "Stiva",\n\t\t"location": "Moscow",\n\t}\n\n\t_, err = hatchet.Filters().Create(\n\t\tcontext.Background(),\n\t\trest.V1CreateFilterRequest{\n\t\t\tWorkflowId: uuid.New(),\n\t\t\tExpression: "input.shouldSkip == false",\n\t\t\tScope: "foobarbaz",\n\t\t\tPayload: &payload,\n\t\t},\n\t)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// > Skip a run\n\tskipPayload := map[string]interface{}{\n\t\t"shouldSkip": true,\n\t}\n\tskipScope := "foobarbaz"\n\terr = hatchet.Events().Push(\n\t\tcontext.Background(),\n\t\t"simple-event:create",\n\t\tskipPayload,\n\t\tclient.WithFilterScope(&skipScope),\n\t)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// > Trigger a run\n\ttriggerPayload := map[string]interface{}{\n\t\t"shouldSkip": false,\n\t}\n\ttriggerScope := "foobarbaz"\n\terr = hatchet.Events().Push(\n\t\tcontext.Background(),\n\t\t"simple-event:create",\n\t\ttriggerPayload,\n\t\tclient.WithFilterScope(&triggerScope),\n\t)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n',
|
||||
source: 'out/go/run/event.go',
|
||||
blocks: {
|
||||
pushing_an_event: {
|
||||
start: 27,
|
||||
stop: 33,
|
||||
},
|
||||
create_a_filter: {
|
||||
start: 36,
|
||||
stop: 50,
|
||||
},
|
||||
skip_a_run: {
|
||||
start: 57,
|
||||
stop: 66,
|
||||
},
|
||||
trigger_a_run: {
|
||||
start: 73,
|
||||
stop: 82,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,13 +0,0 @@
|
||||
import all from './all';
|
||||
import bulk from './bulk';
|
||||
import cron from './cron';
|
||||
import event from './event';
|
||||
import priority from './priority';
|
||||
import simple from './simple';
|
||||
|
||||
export { all };
|
||||
export { bulk };
|
||||
export { cron };
|
||||
export { event };
|
||||
export { priority };
|
||||
export { simple };
|
||||
@@ -1,21 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"context"\n\t"fmt"\n\t"time"\n\n\tv1_workflows "github.com/hatchet-dev/hatchet/examples/go/workflows"\n\t"github.com/hatchet-dev/hatchet/pkg/client"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/joho/godotenv"\n)\n\nfunc priority() {\n\terr := godotenv.Load()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\thatchet, err := v1.NewHatchetClient()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tctx := context.Background()\n\n\tpriorityWorkflow := v1_workflows.Priority(hatchet)\n\n\t// > Running a Task with Priority\n\tpriority := int32(3)\n\n\trunId, err := priorityWorkflow.RunNoWait(ctx, v1_workflows.PriorityInput{\n\t\tUserId: "1234",\n\t}, client.WithPriority(priority))\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(runId)\n\n\t// > Schedule and cron\n\tschedulePriority := int32(3)\n\trunAt := time.Now().Add(time.Minute)\n\n\tscheduledRunId, _ := priorityWorkflow.Schedule(ctx, runAt, v1_workflows.PriorityInput{\n\t\tUserId: "1234",\n\t}, client.WithPriority(schedulePriority))\n\n\tcronId, _ := priorityWorkflow.Cron(ctx, "my-cron", "* * * * *", v1_workflows.PriorityInput{\n\t\tUserId: "1234",\n\t}, client.WithPriority(schedulePriority))\n\n\tfmt.Println(scheduledRunId)\n\tfmt.Println(cronId)\n\n}\n',
|
||||
source: 'out/go/run/priority.go',
|
||||
blocks: {
|
||||
running_a_task_with_priority: {
|
||||
start: 31,
|
||||
stop: 35,
|
||||
},
|
||||
schedule_and_cron: {
|
||||
start: 44,
|
||||
stop: 53,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,29 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"context"\n\t"fmt"\n\t"sync"\n\n\tv1_workflows "github.com/hatchet-dev/hatchet/examples/go/workflows"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/joho/godotenv"\n)\n\nfunc simple() {\n\terr := godotenv.Load()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\thatchet, err := v1.NewHatchetClient()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tctx := context.Background()\n\t// > Running a Task\n\tsimple := v1_workflows.Simple(hatchet)\n\tresult, err := simple.Run(ctx, v1_workflows.SimpleInput{\n\t\tMessage: "Hello, World!",\n\t})\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(result.TransformedMessage)\n\n\t// > Running Multiple Tasks\n\tvar results []string\n\tvar resultsMutex sync.Mutex\n\tvar errs []error\n\tvar errsMutex sync.Mutex\n\n\twg := sync.WaitGroup{}\n\twg.Add(2)\n\n\tgo func() {\n\t\tdefer wg.Done()\n\t\tresult, err := simple.Run(ctx, v1_workflows.SimpleInput{\n\t\t\tMessage: "Hello, World!",\n\t\t})\n\n\t\tif err != nil {\n\t\t\terrsMutex.Lock()\n\t\t\terrs = append(errs, err)\n\t\t\terrsMutex.Unlock()\n\t\t\treturn\n\t\t}\n\n\t\tresultsMutex.Lock()\n\t\tresults = append(results, result.TransformedMessage)\n\t\tresultsMutex.Unlock()\n\t}()\n\n\tgo func() {\n\t\tdefer wg.Done()\n\t\tresult, err := simple.Run(ctx, v1_workflows.SimpleInput{\n\t\t\tMessage: "Hello, Moon!",\n\t\t})\n\n\t\tif err != nil {\n\t\t\terrsMutex.Lock()\n\t\t\terrs = append(errs, err)\n\t\t\terrsMutex.Unlock()\n\t\t\treturn\n\t\t}\n\n\t\tresultsMutex.Lock()\n\t\tresults = append(results, result.TransformedMessage)\n\t\tresultsMutex.Unlock()\n\t}()\n\n\twg.Wait()\n\n\t// > Running a Task Without Waiting\n\tsimple = v1_workflows.Simple(hatchet)\n\trunRef, err := simple.RunNoWait(ctx, v1_workflows.SimpleInput{\n\t\tMessage: "Hello, World!",\n\t})\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// The Run Ref Exposes an ID that can be used to wait for the task to complete\n\t// or check on the status of the task\n\trunId := runRef.RunId()\n\tfmt.Println(runId)\n\n\t// > Subscribing to results\n\t// finally, we can wait for the task to complete and get the result\n\tfinalResult, err := runRef.Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(finalResult)\n}\n',
|
||||
source: 'out/go/run/simple.go',
|
||||
blocks: {
|
||||
running_a_task: {
|
||||
start: 27,
|
||||
stop: 36,
|
||||
},
|
||||
running_multiple_tasks: {
|
||||
start: 39,
|
||||
stop: 83,
|
||||
},
|
||||
running_a_task_without_waiting: {
|
||||
start: 86,
|
||||
stop: 98,
|
||||
},
|
||||
subscribing_to_results: {
|
||||
start: 101,
|
||||
stop: 108,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,3 +0,0 @@
|
||||
import main from './main';
|
||||
|
||||
export { main };
|
||||
@@ -1,17 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"context"\n\t"fmt"\n\t"log"\n\n\t"github.com/hatchet-dev/hatchet/examples/go/streaming/shared"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n)\n\n// > Consume\nfunc main() {\n\thatchet, err := v1.NewHatchetClient()\n\tif err != nil {\n\t\tlog.Fatalf("Failed to create Hatchet client: %v", err)\n\t}\n\n\tctx := context.Background()\n\n\tstreamingWorkflow := shared.StreamingWorkflow(hatchet)\n\n\tworkflowRun, err := streamingWorkflow.RunNoWait(ctx, shared.StreamTaskInput{})\n\tif err != nil {\n\t\tlog.Fatalf("Failed to run workflow: %v", err)\n\t}\n\n\tid := workflowRun.RunId()\n\tstream, err := hatchet.Runs().SubscribeToStream(ctx, id)\n\tif err != nil {\n\t\tlog.Fatalf("Failed to subscribe to stream: %v", err)\n\t}\n\n\tfor content := range stream {\n\t\tfmt.Print(content)\n\t}\n\n\tfmt.Println("\\nStreaming completed!")\n}\n\n',
|
||||
source: 'out/go/streaming/consumer/main.go',
|
||||
blocks: {
|
||||
consume: {
|
||||
start: 13,
|
||||
stop: 40,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,9 +0,0 @@
|
||||
import * as consumer from './consumer';
|
||||
import * as server from './server';
|
||||
import * as shared from './shared';
|
||||
import * as worker from './worker';
|
||||
|
||||
export { consumer };
|
||||
export { server };
|
||||
export { shared };
|
||||
export { worker };
|
||||
@@ -1,3 +0,0 @@
|
||||
import main from './main';
|
||||
|
||||
export { main };
|
||||
@@ -1,17 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"context"\n\t"fmt"\n\t"log"\n\t"net/http"\n\t"time"\n\n\t"github.com/hatchet-dev/hatchet/examples/go/streaming/shared"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n)\n\n// > Server\nfunc main() {\n\thatchet, err := v1.NewHatchetClient()\n\tif err != nil {\n\t\tlog.Fatalf("Failed to create Hatchet client: %v", err)\n\t}\n\n\tstreamingWorkflow := shared.StreamingWorkflow(hatchet)\n\n\thttp.HandleFunc("/stream", func(w http.ResponseWriter, r *http.Request) {\n\t\tctx := context.Background()\n\n\t\tw.Header().Set("Content-Type", "text/plain")\n\t\tw.Header().Set("Cache-Control", "no-cache")\n\t\tw.Header().Set("Connection", "keep-alive")\n\n\t\tworkflowRun, err := streamingWorkflow.RunNoWait(ctx, shared.StreamTaskInput{})\n\t\tif err != nil {\n\t\t\thttp.Error(w, err.Error(), http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\n\t\tstream, err := hatchet.Runs().SubscribeToStream(ctx, workflowRun.RunId())\n\t\tif err != nil {\n\t\t\thttp.Error(w, err.Error(), http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\n\t\tflusher, _ := w.(http.Flusher)\n\t\tfor content := range stream {\n\t\t\tfmt.Fprint(w, content)\n\t\t\tif flusher != nil {\n\t\t\t\tflusher.Flush()\n\t\t\t}\n\t\t}\n\t})\n\n\tserver := &http.Server{\n\t\tAddr: ":8000",\n\t\tReadTimeout: 5 * time.Second,\n\t\tWriteTimeout: 10 * time.Second,\n\t}\n\n\tif err := server.ListenAndServe(); err != nil {\n\t\tlog.Println("Failed to start server:", err)\n\t}\n}\n\n',
|
||||
source: 'out/go/streaming/server/main.go',
|
||||
blocks: {
|
||||
server: {
|
||||
start: 15,
|
||||
stop: 61,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,3 +0,0 @@
|
||||
import task from './task';
|
||||
|
||||
export { task };
|
||||
@@ -1,17 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package shared\n\nimport (\n\t"time"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client/create"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/factory"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype StreamTaskInput struct{}\n\ntype StreamTaskOutput struct {\n\tMessage string `json:"message"`\n}\n\n// > Streaming\nconst annaKarenina = `\nHappy families are all alike; every unhappy family is unhappy in its own way.\n\nEverything was in confusion in the Oblonskys\' house. The wife had discovered that the husband was carrying on an intrigue with a French girl, who had been a governess in their family, and she had announced to her husband that she could not go on living in the same house with him.\n`\n\nfunc createChunks(content string, n int) []string {\n\tvar chunks []string\n\tfor i := 0; i < len(content); i += n {\n\t\tend := i + n\n\t\tif end > len(content) {\n\t\t\tend = len(content)\n\t\t}\n\t\tchunks = append(chunks, content[i:end])\n\t}\n\treturn chunks\n}\n\nfunc StreamTask(ctx worker.HatchetContext, input StreamTaskInput) (*StreamTaskOutput, error) {\n\ttime.Sleep(2 * time.Second)\n\n\tchunks := createChunks(annaKarenina, 10)\n\n\tfor _, chunk := range chunks {\n\t\tctx.PutStream(chunk)\n\t\ttime.Sleep(200 * time.Millisecond)\n\t}\n\n\treturn &StreamTaskOutput{\n\t\tMessage: "Streaming completed",\n\t}, nil\n}\n\n\nfunc StreamingWorkflow(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[StreamTaskInput, StreamTaskOutput] {\n\treturn factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "stream-example",\n\t\t},\n\t\tStreamTask,\n\t\thatchet,\n\t)\n}\n',
|
||||
source: 'out/go/streaming/shared/task.go',
|
||||
blocks: {
|
||||
streaming: {
|
||||
start: 20,
|
||||
stop: 52,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,3 +0,0 @@
|
||||
import main from './main';
|
||||
|
||||
export { main };
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"log"\n\n\t"github.com/hatchet-dev/hatchet/examples/go/streaming/shared"\n\t"github.com/hatchet-dev/hatchet/pkg/cmdutils"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\tv1worker "github.com/hatchet-dev/hatchet/pkg/v1/worker"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n)\n\nfunc main() {\n\thatchet, err := v1.NewHatchetClient()\n\tif err != nil {\n\t\tlog.Fatalf("Failed to create Hatchet client: %v", err)\n\t}\n\n\tstreamingWorkflow := shared.StreamingWorkflow(hatchet)\n\n\tw, err := hatchet.Worker(v1worker.WorkerOpts{\n\t\tName: "streaming-worker",\n\t\tWorkflows: []workflow.WorkflowBase{\n\t\t\tstreamingWorkflow,\n\t\t},\n\t})\n\tif err != nil {\n\t\tlog.Fatalf("Failed to create worker: %v", err)\n\t}\n\n\tinterruptCtx, cancel := cmdutils.NewInterruptContext()\n\tdefer cancel()\n\n\tlog.Println("Starting streaming worker...")\n\n\tif err := w.StartBlocking(interruptCtx); err != nil {\n\t\tlog.Println("Worker failed:", err)\n\t}\n}\n',
|
||||
source: 'out/go/streaming/worker/main.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,3 +0,0 @@
|
||||
import start from './start';
|
||||
|
||||
export { start };
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"fmt"\n\t"os"\n\t"time"\n\n\tv1_workflows "github.com/hatchet-dev/hatchet/examples/go/workflows"\n\t"github.com/hatchet-dev/hatchet/pkg/cmdutils"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/worker"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/joho/godotenv"\n)\n\nfunc main() {\n\terr := godotenv.Load()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\thatchet, err := v1.NewHatchetClient()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Get workflow name from command line arguments\n\tvar workflowName string\n\tif len(os.Args) > 1 {\n\t\tworkflowName = os.Args[1]\n\t\tfmt.Println("workflow name provided:", workflowName)\n\t}\n\n\t// Define workflows map\n\tworkflowMap := map[string][]workflow.WorkflowBase{\n\t\t"dag": {v1_workflows.DagWorkflow(hatchet)},\n\t\t"on-failure": {v1_workflows.OnFailure(hatchet)},\n\t\t"simple": {v1_workflows.Simple(hatchet)},\n\t\t"sleep": {v1_workflows.DurableSleep(hatchet)},\n\t\t"child": {v1_workflows.Parent(hatchet), v1_workflows.Child(hatchet)},\n\t\t"cancellation": {v1_workflows.Cancellation(hatchet)},\n\t\t"timeout": {v1_workflows.Timeout(hatchet)},\n\t\t"sticky": {v1_workflows.Sticky(hatchet), v1_workflows.StickyDag(hatchet), v1_workflows.Child(hatchet)},\n\t\t"retries": {v1_workflows.Retries(hatchet), v1_workflows.RetriesWithCount(hatchet), v1_workflows.WithBackoff(hatchet)},\n\t\t"on-cron": {v1_workflows.OnCron(hatchet)},\n\t\t"non-retryable": {v1_workflows.NonRetryableError(hatchet)},\n\t\t"priority": {v1_workflows.Priority(hatchet)},\n\t}\n\n\t// Add an "all" option that registers all workflows\n\tallWorkflows := []workflow.WorkflowBase{}\n\tfor _, wfs := range workflowMap {\n\t\tallWorkflows = append(allWorkflows, wfs...)\n\t}\n\tworkflowMap["all"] = allWorkflows\n\n\t// Lookup workflow from map\n\tworkflow, ok := workflowMap[workflowName]\n\tif !ok {\n\t\tfmt.Println("Invalid workflow name provided. Usage: go run examples/v1/worker/start.go [workflow-name]")\n\t\tfmt.Println("Available workflows:", getAvailableWorkflows(workflowMap))\n\t\tos.Exit(1)\n\t}\n\n\tvar slots int\n\tif workflowName == "priority" {\n\t\tslots = 1\n\t} else {\n\t\tslots = 100\n\t}\n\n\tworker, err := hatchet.Worker(\n\t\tworker.WorkerOpts{\n\t\t\tName: fmt.Sprintf("%s-worker", workflowName),\n\t\t\tWorkflows: workflow,\n\t\t\tSlots: slots,\n\t\t},\n\t)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tinterruptCtx, cancel := cmdutils.NewInterruptContext()\n\n\terr = worker.StartBlocking(interruptCtx)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tgo func() {\n\t\ttime.Sleep(10 * time.Second)\n\t\tcancel()\n\t}()\n}\n\n// Helper function to get available workflows as a formatted string\nfunc getAvailableWorkflows(workflowMap map[string][]workflow.WorkflowBase) string {\n\tvar workflows string\n\tcount := 0\n\tfor name := range workflowMap {\n\t\tif count > 0 {\n\t\t\tworkflows += ", "\n\t\t}\n\t\tworkflows += fmt.Sprintf("\'%s\'", name)\n\t\tcount++\n\t}\n\treturn workflows\n}\n',
|
||||
source: 'out/go/worker/start.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,17 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package v1_workflows\n\nimport (\n\t"errors"\n\t"time"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client/create"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/factory"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype CancellationInput struct{}\ntype CancellationResult struct {\n\tCompleted bool\n}\n\nfunc Cancellation(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[CancellationInput, CancellationResult] {\n\n\t// > Cancelled task\n\t// Create a task that sleeps for 10 seconds and checks if it was cancelled\n\tcancellation := factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "cancellation-task",\n\t\t}, func(ctx worker.HatchetContext, input CancellationInput) (*CancellationResult, error) {\n\t\t\t// Sleep for 10 seconds\n\t\t\ttime.Sleep(10 * time.Second)\n\n\t\t\t// Check if the context was cancelled\n\t\t\tselect {\n\t\t\tcase <-ctx.Done():\n\t\t\t\treturn nil, errors.New("Task was cancelled")\n\t\t\tdefault:\n\t\t\t\t// Continue execution\n\t\t\t}\n\n\t\t\treturn &CancellationResult{\n\t\t\t\tCompleted: true,\n\t\t\t}, nil\n\t\t},\n\t\thatchet,\n\t)\n\n\treturn cancellation\n}\n',
|
||||
source: 'out/go/workflows/cancellations.go',
|
||||
blocks: {
|
||||
cancelled_task: {
|
||||
start: 22,
|
||||
stop: 43,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package v1_workflows\n\nimport (\n\t"github.com/hatchet-dev/hatchet/pkg/client/create"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/factory"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype ChildInput struct {\n\tN int `json:"n"`\n}\n\ntype ValueOutput struct {\n\tValue int `json:"value"`\n}\n\ntype ParentInput struct {\n\tN int `json:"n"`\n}\n\ntype SumOutput struct {\n\tResult int `json:"result"`\n}\n\nfunc Child(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[ChildInput, ValueOutput] {\n\tchild := factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "child",\n\t\t}, func(ctx worker.HatchetContext, input ChildInput) (*ValueOutput, error) {\n\t\t\treturn &ValueOutput{\n\t\t\t\tValue: input.N,\n\t\t\t}, nil\n\t\t},\n\t\thatchet,\n\t)\n\n\treturn child\n}\n\nfunc Parent(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[ParentInput, SumOutput] {\n\n\tchild := Child(hatchet)\n\tparent := factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "parent",\n\t\t}, func(ctx worker.HatchetContext, input ParentInput) (*SumOutput, error) {\n\n\t\t\tsum := 0\n\n\t\t\t// Launch child workflows in parallel\n\t\t\tresults := make([]*ValueOutput, 0, input.N)\n\t\t\tfor j := 0; j < input.N; j++ {\n\t\t\t\tresult, err := child.RunAsChild(ctx, ChildInput{N: j}, workflow.RunAsChildOpts{})\n\n\t\t\t\tif err != nil {\n\t\t\t\t\t// firstErr = err\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\n\t\t\t\tresults = append(results, result)\n\n\t\t\t}\n\n\t\t\t// Sum results from all children\n\t\t\tfor _, result := range results {\n\t\t\t\tsum += result.Value\n\t\t\t}\n\n\t\t\treturn &SumOutput{\n\t\t\t\tResult: sum,\n\t\t\t}, nil\n\t\t},\n\t\thatchet,\n\t)\n\n\treturn parent\n}\n',
|
||||
source: 'out/go/workflows/child-workflows.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
File diff suppressed because one or more lines are too long
@@ -1,21 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package v1_workflows\n\nimport (\n\t"math/rand"\n\t"time"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client/create"\n\t"github.com/hatchet-dev/hatchet/pkg/client/types"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/factory"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype ConcurrencyInput struct {\n\tMessage string\n\tTier string\n\tAccount string\n}\n\ntype TransformedOutput struct {\n\tTransformedMessage string\n}\n\nfunc ConcurrencyRoundRobin(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[ConcurrencyInput, TransformedOutput] {\n\t// > Concurrency Strategy With Key\n\tvar maxRuns int32 = 1\n\tstrategy := types.GroupRoundRobin\n\n\tconcurrency := factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "simple-concurrency",\n\t\t\tConcurrency: []*types.Concurrency{\n\t\t\t\t{\n\t\t\t\t\tExpression: "input.GroupKey",\n\t\t\t\t\tMaxRuns: &maxRuns,\n\t\t\t\t\tLimitStrategy: &strategy,\n\t\t\t\t},\n\t\t\t},\n\t\t}, func(ctx worker.HatchetContext, input ConcurrencyInput) (*TransformedOutput, error) {\n\t\t\t// Random sleep between 200ms and 1000ms\n\t\t\ttime.Sleep(time.Duration(200+rand.Intn(800)) * time.Millisecond)\n\n\t\t\treturn &TransformedOutput{\n\t\t\t\tTransformedMessage: input.Message,\n\t\t\t}, nil\n\t\t},\n\t\thatchet,\n\t)\n\n\treturn concurrency\n}\n\nfunc MultipleConcurrencyKeys(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[ConcurrencyInput, TransformedOutput] {\n\t// > Multiple Concurrency Keys\n\tstrategy := types.GroupRoundRobin\n\tvar maxRuns int32 = 20\n\n\tconcurrency := factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "simple-concurrency",\n\t\t\tConcurrency: []*types.Concurrency{\n\t\t\t\t{\n\t\t\t\t\tExpression: "input.Tier",\n\t\t\t\t\tMaxRuns: &maxRuns,\n\t\t\t\t\tLimitStrategy: &strategy,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tExpression: "input.Account",\n\t\t\t\t\tMaxRuns: &maxRuns,\n\t\t\t\t\tLimitStrategy: &strategy,\n\t\t\t\t},\n\t\t\t},\n\t\t}, func(ctx worker.HatchetContext, input ConcurrencyInput) (*TransformedOutput, error) {\n\t\t\t// Random sleep between 200ms and 1000ms\n\t\t\ttime.Sleep(time.Duration(200+rand.Intn(800)) * time.Millisecond)\n\n\t\t\treturn &TransformedOutput{\n\t\t\t\tTransformedMessage: input.Message,\n\t\t\t}, nil\n\t\t},\n\t\thatchet,\n\t)\n\n\treturn concurrency\n}\n',
|
||||
source: 'out/go/workflows/concurrency-rr.go',
|
||||
blocks: {
|
||||
concurrency_strategy_with_key: {
|
||||
start: 27,
|
||||
stop: 49,
|
||||
},
|
||||
multiple_concurrency_keys: {
|
||||
start: 56,
|
||||
stop: 83,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package v1_workflows\n\nimport (\n\t"fmt"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client/create"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/factory"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype DagWithConditionsInput struct {\n\tMessage string\n}\n\ntype DagWithConditionsResult struct {\n\tStep1 SimpleOutput\n\tStep2 SimpleOutput\n}\n\ntype conditionOpts = create.WorkflowTask[DagWithConditionsInput, DagWithConditionsResult]\n\nfunc DagWithConditionsWorkflow(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[DagWithConditionsInput, DagWithConditionsResult] {\n\n\tsimple := factory.NewWorkflow[DagWithConditionsInput, DagWithConditionsResult](\n\t\tcreate.WorkflowCreateOpts[DagWithConditionsInput]{\n\t\t\tName: "simple-dag",\n\t\t},\n\t\thatchet,\n\t)\n\n\tstep1 := simple.Task(\n\t\tconditionOpts{\n\t\t\tName: "Step1",\n\t\t}, func(ctx worker.HatchetContext, input DagWithConditionsInput) (interface{}, error) {\n\t\t\treturn &SimpleOutput{\n\t\t\t\tStep: 1,\n\t\t\t}, nil\n\t\t},\n\t)\n\n\tsimple.Task(\n\t\tconditionOpts{\n\t\t\tName: "Step2",\n\t\t\tParents: []create.NamedTask{\n\t\t\t\tstep1,\n\t\t\t},\n\t\t}, func(ctx worker.HatchetContext, input DagWithConditionsInput) (interface{}, error) {\n\n\t\t\tvar step1Output SimpleOutput\n\t\t\terr := ctx.ParentOutput(step1, &step1Output)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\t\tfmt.Println(step1Output.Step)\n\n\t\t\treturn &SimpleOutput{\n\t\t\t\tStep: 2,\n\t\t\t}, nil\n\t\t},\n\t)\n\n\treturn simple\n}\n',
|
||||
source: 'out/go/workflows/dag-with-conditions.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,25 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package v1_workflows\n\nimport (\n\t"github.com/hatchet-dev/hatchet/pkg/client/create"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/factory"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype DagInput struct {\n\tMessage string\n}\n\ntype SimpleOutput struct {\n\tStep int\n}\n\ntype DagResult struct {\n\tStep1 SimpleOutput\n\tStep2 SimpleOutput\n}\n\nfunc DagWorkflow(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[DagInput, DagResult] {\n\t// > Declaring a Workflow\n\tsimple := factory.NewWorkflow[DagInput, DagResult](\n\t\tcreate.WorkflowCreateOpts[DagInput]{\n\t\t\tName: "simple-dag",\n\n\t\t},\n\t\thatchet,\n\t)\n\n\t// > Defining a Task\n\tsimple.Task(\n\t\tcreate.WorkflowTask[DagInput, DagResult]{\n\t\t\tName: "step",\n\t\t}, func(ctx worker.HatchetContext, input DagInput) (interface{}, error) {\n\t\t\treturn &SimpleOutput{\n\t\t\t\tStep: 1,\n\t\t\t}, nil\n\t\t},\n\t)\n\n\t// > Adding a Task with a parent\n\tstep1 := simple.Task(\n\t\tcreate.WorkflowTask[DagInput, DagResult]{\n\t\t\tName: "step-1",\n\t\t}, func(ctx worker.HatchetContext, input DagInput) (interface{}, error) {\n\t\t\treturn &SimpleOutput{\n\t\t\t\tStep: 1,\n\t\t\t}, nil\n\t\t},\n\t)\n\n\tsimple.Task(\n\t\tcreate.WorkflowTask[DagInput, DagResult]{\n\t\t\tName: "step-2",\n\t\t\tParents: []create.NamedTask{\n\t\t\t\tstep1,\n\t\t\t},\n\t\t}, func(ctx worker.HatchetContext, input DagInput) (interface{}, error) {\n\t\t\t// Get the output of the parent task\n\t\t\tvar step1Output SimpleOutput\n\t\t\terr := ctx.ParentOutput(step1, &step1Output)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\t\treturn &SimpleOutput{\n\t\t\t\tStep: 2,\n\t\t\t}, nil\n\t\t},\n\t)\n\n\treturn simple\n}\n',
|
||||
source: 'out/go/workflows/dag.go',
|
||||
blocks: {
|
||||
declaring_a_workflow: {
|
||||
start: 26,
|
||||
stop: 32,
|
||||
},
|
||||
defining_a_task: {
|
||||
start: 35,
|
||||
stop: 43,
|
||||
},
|
||||
adding_a_task_with_a_parent: {
|
||||
start: 46,
|
||||
stop: 74,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,21 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package v1_workflows\n\nimport (\n\t"github.com/hatchet-dev/hatchet/pkg/client/create"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/factory"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype DurableEventInput struct {\n\tMessage string\n}\n\ntype EventData struct {\n\tMessage string\n}\n\ntype DurableEventOutput struct {\n\tData EventData\n}\n\nfunc DurableEvent(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[DurableEventInput, DurableEventOutput] {\n\t// > Durable Event\n\tdurableEventTask := factory.NewDurableTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "durable-event",\n\t\t},\n\t\tfunc(ctx worker.DurableHatchetContext, input DurableEventInput) (*DurableEventOutput, error) {\n\t\t\teventData, err := ctx.WaitForEvent("user:update", "")\n\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\t\tv := EventData{}\n\t\t\terr = eventData.Unmarshal(&v)\n\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\t\treturn &DurableEventOutput{\n\t\t\t\tData: v,\n\t\t\t}, nil\n\t\t},\n\t\thatchet,\n\t)\n\n\tfactory.NewDurableTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "durable-event",\n\t\t},\n\t\tfunc(ctx worker.DurableHatchetContext, input DurableEventInput) (*DurableEventOutput, error) {\n\t\t\t// > Durable Event With Filter\n\t\t\teventData, err := ctx.WaitForEvent("user:update", "input.user_id == \'1234\'")\n\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\t\tv := EventData{}\n\t\t\terr = eventData.Unmarshal(&v)\n\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\t\treturn &DurableEventOutput{\n\t\t\t\tData: v,\n\t\t\t}, nil\n\t\t},\n\t\thatchet,\n\t)\n\n\treturn durableEventTask\n}\n',
|
||||
source: 'out/go/workflows/durable-event.go',
|
||||
blocks: {
|
||||
durable_event: {
|
||||
start: 25,
|
||||
stop: 48,
|
||||
},
|
||||
durable_event_with_filter: {
|
||||
start: 56,
|
||||
stop: 56,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,17 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package v1_workflows\n\nimport (\n\t"strings"\n\t"time"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client/create"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/factory"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype DurableSleepInput struct {\n\tMessage string\n}\n\ntype DurableSleepOutput struct {\n\tTransformedMessage string\n}\n\nfunc DurableSleep(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[DurableSleepInput, DurableSleepOutput] {\n\t// > Durable Sleep\n\tsimple := factory.NewDurableTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "durable-sleep",\n\t\t},\n\t\tfunc(ctx worker.DurableHatchetContext, input DurableSleepInput) (*DurableSleepOutput, error) {\n\t\t\t_, err := ctx.SleepFor(10 * time.Second)\n\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\t\treturn &DurableSleepOutput{\n\t\t\t\tTransformedMessage: strings.ToLower(input.Message),\n\t\t\t}, nil\n\t\t},\n\t\thatchet,\n\t)\n\n\treturn simple\n}\n',
|
||||
source: 'out/go/workflows/durable-sleep.go',
|
||||
blocks: {
|
||||
durable_sleep: {
|
||||
start: 24,
|
||||
stop: 40,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,37 +0,0 @@
|
||||
import cancellations from './cancellations';
|
||||
import child_workflows from './child-workflows';
|
||||
import complex_conditions from './complex-conditions';
|
||||
import concurrency_rr from './concurrency-rr';
|
||||
import dag_with_conditions from './dag-with-conditions';
|
||||
import dag from './dag';
|
||||
import durable_event from './durable-event';
|
||||
import durable_sleep from './durable-sleep';
|
||||
import non_retryable_error from './non-retryable-error';
|
||||
import on_cron from './on-cron';
|
||||
import on_event from './on-event';
|
||||
import on_failure from './on-failure';
|
||||
import priority from './priority';
|
||||
import ratelimit from './ratelimit';
|
||||
import retries from './retries';
|
||||
import simple from './simple';
|
||||
import sticky from './sticky';
|
||||
import timeouts from './timeouts';
|
||||
|
||||
export { cancellations };
|
||||
export { child_workflows };
|
||||
export { complex_conditions };
|
||||
export { concurrency_rr };
|
||||
export { dag_with_conditions };
|
||||
export { dag };
|
||||
export { durable_event };
|
||||
export { durable_sleep };
|
||||
export { non_retryable_error };
|
||||
export { on_cron };
|
||||
export { on_event };
|
||||
export { on_failure };
|
||||
export { priority };
|
||||
export { ratelimit };
|
||||
export { retries };
|
||||
export { simple };
|
||||
export { sticky };
|
||||
export { timeouts };
|
||||
@@ -1,17 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package v1_workflows\n\nimport (\n\t"errors"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client/create"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/factory"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype NonRetryableInput struct{}\ntype NonRetryableResult struct{}\n\n// NonRetryableError returns a workflow which throws a non-retryable error\nfunc NonRetryableError(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[NonRetryableInput, NonRetryableResult] {\n\t// > Non Retryable Error\n\tretries := factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "non-retryable-task",\n\t\t\tRetries: 3,\n\t\t}, func(ctx worker.HatchetContext, input NonRetryableInput) (*NonRetryableResult, error) {\n\t\t\treturn nil, worker.NewNonRetryableError(errors.New("intentional failure"))\n\t\t},\n\t\thatchet,\n\t)\n\n\treturn retries\n}\n',
|
||||
source: 'out/go/workflows/non-retryable-error.go',
|
||||
blocks: {
|
||||
non_retryable_error: {
|
||||
start: 19,
|
||||
stop: 27,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,17 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package v1_workflows\n\nimport (\n\t"strings"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client/create"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/factory"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype OnCronInput struct {\n\tMessage string `json:"Message"`\n}\n\ntype JobResult struct {\n\tTransformedMessage string `json:"TransformedMessage"`\n}\n\ntype OnCronOutput struct {\n\tJob JobResult `json:"job"`\n}\n\n// > Workflow Definition Cron Trigger\nfunc OnCron(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[OnCronInput, OnCronOutput] {\n\t// Create a standalone task that transforms a message\n\tcronTask := factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "on-cron-task",\n\t\t\t// 👀 add a cron expression\n\t\t\tOnCron: []string{"0 0 * * *"}, // Run every day at midnight\n\t\t},\n\t\tfunc(ctx worker.HatchetContext, input OnCronInput) (*OnCronOutput, error) {\n\t\t\treturn &OnCronOutput{\n\t\t\t\tJob: JobResult{\n\t\t\t\t\tTransformedMessage: strings.ToLower(input.Message),\n\t\t\t\t},\n\t\t\t}, nil\n\t\t},\n\t\thatchet,\n\t)\n\n\treturn cronTask\n}\n\n',
|
||||
source: 'out/go/workflows/on-cron.go',
|
||||
blocks: {
|
||||
workflow_definition_cron_trigger: {
|
||||
start: 26,
|
||||
stop: 46,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,25 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package v1_workflows\n\nimport (\n\t"fmt"\n\t"strings"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client/create"\n\t"github.com/hatchet-dev/hatchet/pkg/client/types"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/factory"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype EventInput struct {\n\tMessage string\n}\n\ntype LowerTaskOutput struct {\n\tTransformedMessage string\n}\n\ntype UpperTaskOutput struct {\n\tTransformedMessage string\n}\n\n// > Run workflow on event\nconst SimpleEvent = "simple-event:create"\n\nfunc Lower(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[EventInput, LowerTaskOutput] {\n\treturn factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "lower",\n\t\t\t// 👀 Declare the event that will trigger the workflow\n\t\t\tOnEvents: []string{SimpleEvent},\n\t\t}, func(ctx worker.HatchetContext, input EventInput) (*LowerTaskOutput, error) {\n\t\t\t// Transform the input message to lowercase\n\t\t\treturn &LowerTaskOutput{\n\t\t\t\tTransformedMessage: strings.ToLower(input.Message),\n\t\t\t}, nil\n\t\t},\n\t\thatchet,\n\t)\n}\n\n\n// > Accessing the filter payload\nfunc accessFilterPayload(ctx worker.HatchetContext, input EventInput) (*LowerTaskOutput, error) {\n\tfmt.Println(ctx.FilterPayload())\n\treturn &LowerTaskOutput{\n\t\tTransformedMessage: strings.ToLower(input.Message),\n\t}, nil\n}\n\n\n// > Declare with filter\nfunc LowerWithFilter(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[EventInput, LowerTaskOutput] {\n\treturn factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "lower",\n\t\t\t// 👀 Declare the event that will trigger the workflow\n\t\t\tOnEvents: []string{SimpleEvent},\n\t\t\tDefaultFilters: []types.DefaultFilter{{\n\t\t\t\tExpression: "true",\n\t\t\t\tScope: "example-scope",\n\t\t\t\tPayload: map[string]interface{}{\n\t\t\t\t\t"main_character": "Anna",\n\t\t\t\t\t"supporting_character": "Stiva",\n\t\t\t\t\t"location": "Moscow"},\n\t\t\t}},\n\t\t}, accessFilterPayload,\n\t\thatchet,\n\t)\n}\n\n\nfunc Upper(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[EventInput, UpperTaskOutput] {\n\treturn factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "upper",\n\t\t\tOnEvents: []string{SimpleEvent},\n\t\t},\n\t\tfunc(ctx worker.HatchetContext, input EventInput) (*UpperTaskOutput, error) {\n\t\t\treturn &UpperTaskOutput{\n\t\t\t\tTransformedMessage: strings.ToUpper(input.Message),\n\t\t\t}, nil\n\t\t},\n\t\thatchet,\n\t)\n}\n',
|
||||
source: 'out/go/workflows/on-event.go',
|
||||
blocks: {
|
||||
run_workflow_on_event: {
|
||||
start: 28,
|
||||
stop: 45,
|
||||
},
|
||||
accessing_the_filter_payload: {
|
||||
start: 48,
|
||||
stop: 54,
|
||||
},
|
||||
declare_with_filter: {
|
||||
start: 57,
|
||||
stop: 75,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package v1_workflows\n\nimport (\n\t"errors"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client/create"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/factory"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype AlwaysFailsOutput struct {\n\tTransformedMessage string\n}\n\ntype OnFailureOutput struct {\n\tFailureRan bool\n}\n\ntype OnFailureSuccessResult struct {\n\tAlwaysFails AlwaysFailsOutput\n}\n\nfunc OnFailure(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[any, OnFailureSuccessResult] {\n\n\tsimple := factory.NewWorkflow[any, OnFailureSuccessResult](\n\t\tcreate.WorkflowCreateOpts[any]{\n\t\t\tName: "on-failure",\n\t\t},\n\t\thatchet,\n\t)\n\n\tsimple.Task(\n\t\tcreate.WorkflowTask[any, OnFailureSuccessResult]{\n\t\t\tName: "AlwaysFails",\n\t\t},\n\t\tfunc(ctx worker.HatchetContext, _ any) (interface{}, error) {\n\t\t\treturn &AlwaysFailsOutput{\n\t\t\t\tTransformedMessage: "always fails",\n\t\t\t}, errors.New("always fails")\n\t\t},\n\t)\n\n\tsimple.OnFailure(\n\t\tcreate.WorkflowOnFailureTask[any, OnFailureSuccessResult]{},\n\t\tfunc(ctx worker.HatchetContext, _ any) (interface{}, error) {\n\t\t\treturn &OnFailureOutput{\n\t\t\t\tFailureRan: true,\n\t\t\t}, nil\n\t\t},\n\t)\n\n\treturn simple\n}\n',
|
||||
source: 'out/go/workflows/on-failure.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,21 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package v1_workflows\n\nimport (\n\t"time"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client/create"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/factory"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype PriorityInput struct {\n\tUserId string `json:"userId"`\n}\n\ntype PriorityOutput struct {\n\tTransformedMessage string `json:"TransformedMessage"`\n}\n\ntype Result struct {\n\tStep PriorityOutput\n}\n\nfunc Priority(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[PriorityInput, Result] {\n\t// Create a standalone task that transforms a message\n\n\t// > Default priority\n\tdefaultPriority := int32(1)\n\n\tworkflow := factory.NewWorkflow[PriorityInput, Result](\n\t\tcreate.WorkflowCreateOpts[PriorityInput]{\n\t\t\tName: "priority",\n\t\t\tDefaultPriority: &defaultPriority,\n\t\t},\n\t\thatchet,\n\t)\n\n\t// > Defining a Task\n\tworkflow.Task(\n\t\tcreate.WorkflowTask[PriorityInput, Result]{\n\t\t\tName: "step",\n\t\t}, func(ctx worker.HatchetContext, input PriorityInput) (interface{}, error) {\n\t\t\ttime.Sleep(time.Second * 5)\n\t\t\treturn &PriorityOutput{\n\t\t\t\tTransformedMessage: input.UserId,\n\t\t\t}, nil\n\t\t},\n\t)\n\treturn workflow\n}\n\n',
|
||||
source: 'out/go/workflows/priority.go',
|
||||
blocks: {
|
||||
default_priority: {
|
||||
start: 29,
|
||||
stop: 37,
|
||||
},
|
||||
defining_a_task: {
|
||||
start: 40,
|
||||
stop: 49,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,25 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package v1_workflows\n\nimport (\n\t"strings"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client/create"\n\t"github.com/hatchet-dev/hatchet/pkg/client/types"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/factory"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/features"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype RateLimitInput struct {\n\tUserId string `json:"userId"`\n}\n\ntype RateLimitOutput struct {\n\tTransformedMessage string `json:"TransformedMessage"`\n}\n\nfunc upsertRateLimit(hatchet v1.HatchetClient) {\n\t// > Upsert Rate Limit\n\thatchet.RateLimits().Upsert(\n\t\tfeatures.CreateRatelimitOpts{\n\t\t\tKey: "api-service-rate-limit",\n\t\t\tLimit: 10,\n\t\t\tDuration: types.Second,\n\t\t},\n\t)\n}\n\n// > Static Rate Limit\nfunc StaticRateLimit(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[RateLimitInput, RateLimitOutput] {\n\t// Create a standalone task that transforms a message\n\n\t// define the parameters for the rate limit\n\trateLimitKey := "api-service-rate-limit"\n\tunits := 1\n\n\trateLimitTask := factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "rate-limit-task",\n\t\t\t// 👀 add a static rate limit\n\t\t\tRateLimits: []*types.RateLimit{\n\t\t\t\t{\n\t\t\t\t\tKey: rateLimitKey,\n\t\t\t\t\tUnits: &units,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tfunc(ctx worker.HatchetContext, input RateLimitInput) (*RateLimitOutput, error) {\n\t\t\treturn &RateLimitOutput{\n\t\t\t\tTransformedMessage: strings.ToLower(input.UserId),\n\t\t\t}, nil\n\t\t},\n\t\thatchet,\n\t)\n\n\treturn rateLimitTask\n}\n\n\n// > Dynamic Rate Limit\nfunc RateLimit(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[RateLimitInput, RateLimitOutput] {\n\t// Create a standalone task that transforms a message\n\n\t// define the parameters for the rate limit\n\texpression := "input.userId"\n\tunits := 1\n\tduration := types.Second\n\n\trateLimitTask := factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "rate-limit-task",\n\t\t\t// 👀 add a dynamic rate limit\n\t\t\tRateLimits: []*types.RateLimit{\n\t\t\t\t{\n\t\t\t\t\tKeyExpr: &expression,\n\t\t\t\t\tUnits: &units,\n\t\t\t\t\tDuration: &duration,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tfunc(ctx worker.HatchetContext, input RateLimitInput) (*RateLimitOutput, error) {\n\t\t\treturn &RateLimitOutput{\n\t\t\t\tTransformedMessage: strings.ToLower(input.UserId),\n\t\t\t}, nil\n\t\t},\n\t\thatchet,\n\t)\n\n\treturn rateLimitTask\n}\n\n',
|
||||
source: 'out/go/workflows/ratelimit.go',
|
||||
blocks: {
|
||||
upsert_rate_limit: {
|
||||
start: 25,
|
||||
stop: 31,
|
||||
},
|
||||
static_rate_limit: {
|
||||
start: 35,
|
||||
stop: 63,
|
||||
},
|
||||
dynamic_rate_limit: {
|
||||
start: 66,
|
||||
stop: 96,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,25 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package v1_workflows\n\nimport (\n\t"errors"\n\t"fmt"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client/create"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/factory"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype RetriesInput struct{}\ntype RetriesResult struct{}\n\n// Simple retries example that always fails\nfunc Retries(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[RetriesInput, RetriesResult] {\n\t// > Simple Step Retries\n\tretries := factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "retries-task",\n\t\t\tRetries: 3,\n\t\t}, func(ctx worker.HatchetContext, input RetriesInput) (*RetriesResult, error) {\n\t\t\treturn nil, errors.New("intentional failure")\n\t\t},\n\t\thatchet,\n\t)\n\n\treturn retries\n}\n\ntype RetriesWithCountInput struct{}\ntype RetriesWithCountResult struct {\n\tMessage string `json:"message"`\n}\n\n// Retries example that succeeds after a certain number of retries\nfunc RetriesWithCount(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[RetriesWithCountInput, RetriesWithCountResult] {\n\t// > Retries with Count\n\tretriesWithCount := factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "fail-twice-task",\n\t\t\tRetries: 3,\n\t\t}, func(ctx worker.HatchetContext, input RetriesWithCountInput) (*RetriesWithCountResult, error) {\n\t\t\t// Get the current retry count\n\t\t\tretryCount := ctx.RetryCount()\n\n\t\t\tfmt.Printf("Retry count: %d\\n", retryCount)\n\n\t\t\tif retryCount < 2 {\n\t\t\t\treturn nil, errors.New("intentional failure")\n\t\t\t}\n\n\t\t\treturn &RetriesWithCountResult{\n\t\t\t\tMessage: "success",\n\t\t\t}, nil\n\t\t},\n\t\thatchet,\n\t)\n\n\treturn retriesWithCount\n}\n\ntype BackoffInput struct{}\ntype BackoffResult struct{}\n\n// Retries example with simple backoff (no configuration in this API version)\nfunc WithBackoff(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[BackoffInput, BackoffResult] {\n\t// > Retries with Backoff\n\twithBackoff := factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "with-backoff-task",\n\t\t\t// 👀 Maximum number of seconds to wait between retries\n\t\t\tRetries: 3,\n\t\t\t// 👀 Factor to increase the wait time between retries.\n\t\t\tRetryBackoffFactor: 2,\n\t\t\t// 👀 Maximum number of seconds to wait between retries\n\t\t\t// This sequence will be 2s, 4s, 8s, 10s, 10s, 10s... due to the maxSeconds limit\n\t\t\tRetryMaxBackoffSeconds: 10,\n\t\t}, func(ctx worker.HatchetContext, input BackoffInput) (*BackoffResult, error) {\n\t\t\treturn nil, errors.New("intentional failure")\n\t\t},\n\t\thatchet,\n\t)\n\n\treturn withBackoff\n}\n',
|
||||
source: 'out/go/workflows/retries.go',
|
||||
blocks: {
|
||||
simple_step_retries: {
|
||||
start: 20,
|
||||
stop: 28,
|
||||
},
|
||||
retries_with_count: {
|
||||
start: 41,
|
||||
stop: 60,
|
||||
},
|
||||
retries_with_backoff: {
|
||||
start: 71,
|
||||
stop: 85,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,29 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package v1_workflows\n\nimport (\n\t"context"\n\t"fmt"\n\t"strings"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client/create"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/factory"\n\tv1worker "github.com/hatchet-dev/hatchet/pkg/v1/worker"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype SimpleInput struct {\n\tMessage string\n}\ntype SimpleResult struct {\n\tTransformedMessage string\n}\n\nfunc Simple(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[SimpleInput, SimpleResult] {\n\n\t// Create a simple standalone task using the task factory\n\t// Note the use of typed generics for both input and output\n\n\t// > Declaring a Task\n\tsimple := factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "simple-task",\n\t\t}, func(ctx worker.HatchetContext, input SimpleInput) (*SimpleResult, error) {\n\t\t\t// Transform the input message to lowercase\n\t\t\treturn &SimpleResult{\n\t\t\t\tTransformedMessage: strings.ToLower(input.Message),\n\t\t\t}, nil\n\t\t},\n\t\thatchet,\n\t)\n\n\t// Example of running a task\n\t_ = func() error {\n\t\t// > Running a Task\n\t\tresult, err := simple.Run(context.Background(), SimpleInput{Message: "Hello, World!"})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tfmt.Println(result.TransformedMessage)\n\t\treturn nil\n\t}\n\n\t// Example of registering a task on a worker\n\t_ = func() error {\n\t\t// > Declaring a Worker\n\t\tw, err := hatchet.Worker(v1worker.WorkerOpts{\n\t\t\tName: "simple-worker",\n\t\t\tWorkflows: []workflow.WorkflowBase{\n\t\t\t\tsimple,\n\t\t\t},\n\t\t})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\terr = w.StartBlocking(context.Background())\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\treturn nil\n\t}\n\n\treturn simple\n}\n\nfunc ParentTask(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[SimpleInput, SimpleResult] {\n\n\t// > Spawning Tasks from within a Task\n\tsimple := Simple(hatchet)\n\n\tparent := factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "parent-task",\n\t\t}, func(ctx worker.HatchetContext, input SimpleInput) (*SimpleResult, error) {\n\n\t\t\t// Run the child task\n\t\t\tchild, err := workflow.RunChildWorkflow(ctx, simple, SimpleInput{Message: input.Message})\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\t\t// Transform the input message to lowercase\n\t\t\treturn &SimpleResult{\n\t\t\t\tTransformedMessage: child.TransformedMessage,\n\t\t\t}, nil\n\t\t},\n\t\thatchet,\n\t)\n\n\treturn parent\n}\n',
|
||||
source: 'out/go/workflows/simple.go',
|
||||
blocks: {
|
||||
declaring_a_task: {
|
||||
start: 29,
|
||||
stop: 39,
|
||||
},
|
||||
running_a_task: {
|
||||
start: 44,
|
||||
stop: 48,
|
||||
},
|
||||
declaring_a_worker: {
|
||||
start: 55,
|
||||
stop: 67,
|
||||
},
|
||||
spawning_tasks_from_within_a_task: {
|
||||
start: 77,
|
||||
stop: 96,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package v1_workflows\n\nimport (\n\t"fmt"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client/create"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/factory"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype StickyInput struct{}\n\ntype StickyResult struct {\n\tResult string `json:"result"`\n}\n\ntype StickyDagResult struct {\n\tStickyTask1 StickyResult `json:"sticky-task-1"`\n\tStickyTask2 StickyResult `json:"sticky-task-2"`\n}\n\nfunc StickyDag(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[StickyInput, StickyDagResult] {\n\tstickyDag := factory.NewWorkflow[StickyInput, StickyDagResult](\n\t\tcreate.WorkflowCreateOpts[StickyInput]{\n\t\t\tName: "sticky-dag",\n\t\t},\n\t\thatchet,\n\t)\n\n\tstickyDag.Task(\n\t\tcreate.WorkflowTask[StickyInput, StickyDagResult]{\n\t\t\tName: "sticky-task",\n\t\t},\n\t\tfunc(ctx worker.HatchetContext, input StickyInput) (interface{}, error) {\n\t\t\tworkerId := ctx.Worker().ID()\n\n\t\t\treturn &StickyResult{\n\t\t\t\tResult: workerId,\n\t\t\t}, nil\n\t\t},\n\t)\n\n\tstickyDag.Task(\n\t\tcreate.WorkflowTask[StickyInput, StickyDagResult]{\n\t\t\tName: "sticky-task-2",\n\t\t},\n\t\tfunc(ctx worker.HatchetContext, input StickyInput) (interface{}, error) {\n\t\t\tworkerId := ctx.Worker().ID()\n\n\t\t\treturn &StickyResult{\n\t\t\t\tResult: workerId,\n\t\t\t}, nil\n\t\t},\n\t)\n\n\treturn stickyDag\n}\n\nfunc Sticky(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[StickyInput, StickyResult] {\n\tsticky := factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "sticky-task",\n\t\t\tRetries: 3,\n\t\t}, func(ctx worker.HatchetContext, input StickyInput) (*StickyResult, error) {\n\t\t\t// Run a child workflow on the same worker\n\t\t\tchildWorkflow := Child(hatchet)\n\t\t\tsticky := true\n\t\t\tchildResult, err := childWorkflow.RunAsChild(ctx, ChildInput{N: 1}, workflow.RunAsChildOpts{\n\t\t\t\tSticky: &sticky,\n\t\t\t})\n\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\t\treturn &StickyResult{\n\t\t\t\tResult: fmt.Sprintf("child-result-%d", childResult.Value),\n\t\t\t}, nil\n\t\t},\n\t\thatchet,\n\t)\n\n\treturn sticky\n}\n',
|
||||
source: 'out/go/workflows/sticky.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,21 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package v1_workflows\n\nimport (\n\t"errors"\n\t"time"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client/create"\n\tv1 "github.com/hatchet-dev/hatchet/pkg/v1"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/factory"\n\t"github.com/hatchet-dev/hatchet/pkg/v1/workflow"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype TimeoutInput struct{}\ntype TimeoutResult struct {\n\tCompleted bool\n}\n\nfunc Timeout(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[TimeoutInput, TimeoutResult] {\n\n\t// > Execution Timeout\n\t// Create a task with a timeout of 3 seconds that tries to sleep for 10 seconds\n\ttimeout := factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "timeout-task",\n\t\t\tExecutionTimeout: 3 * time.Second, // Task will timeout after 3 seconds\n\t\t}, func(ctx worker.HatchetContext, input TimeoutInput) (*TimeoutResult, error) {\n\t\t\t// Sleep for 10 seconds\n\t\t\ttime.Sleep(10 * time.Second)\n\n\t\t\t// Check if the context was cancelled due to timeout\n\t\t\tselect {\n\t\t\tcase <-ctx.Done():\n\t\t\t\treturn nil, errors.New("TASK TIMED OUT")\n\t\t\tdefault:\n\t\t\t\t// Continue execution\n\t\t\t}\n\n\t\t\treturn &TimeoutResult{\n\t\t\t\tCompleted: true,\n\t\t\t}, nil\n\t\t},\n\t\thatchet,\n\t)\n\n\treturn timeout\n}\n\nfunc RefreshTimeout(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[TimeoutInput, TimeoutResult] {\n\n\t// > Refresh Timeout\n\ttimeout := factory.NewTask(\n\t\tcreate.StandaloneTask{\n\t\t\tName: "timeout-task",\n\t\t\tExecutionTimeout: 3 * time.Second, // Task will timeout after 3 seconds\n\t\t}, func(ctx worker.HatchetContext, input TimeoutInput) (*TimeoutResult, error) {\n\n\t\t\t// Refresh the timeout by 10 seconds (new timeout will be 13 seconds)\n\t\t\tctx.RefreshTimeout("10s")\n\n\t\t\t// Sleep for 10 seconds\n\t\t\ttime.Sleep(10 * time.Second)\n\n\t\t\t// Check if the context was cancelled due to timeout\n\t\t\tselect {\n\t\t\tcase <-ctx.Done():\n\t\t\t\treturn nil, errors.New("TASK TIMED OUT")\n\t\t\tdefault:\n\t\t\t\t// Continue execution\n\t\t\t}\n\n\t\t\treturn &TimeoutResult{\n\t\t\t\tCompleted: true,\n\t\t\t}, nil\n\t\t},\n\t\thatchet,\n\t)\n\n\treturn timeout\n}\n',
|
||||
source: 'out/go/workflows/timeouts.go',
|
||||
blocks: {
|
||||
execution_timeout: {
|
||||
start: 22,
|
||||
stop: 44,
|
||||
},
|
||||
refresh_timeout: {
|
||||
start: 52,
|
||||
stop: 77,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,5 +0,0 @@
|
||||
import main from './main';
|
||||
import run from './run';
|
||||
|
||||
export { main };
|
||||
export { run };
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"fmt"\n\n\t"github.com/joho/godotenv"\n\n\t"github.com/hatchet-dev/hatchet/pkg/cmdutils"\n)\n\ntype userCreateEvent struct {\n\tUsername string `json:"username"`\n\tUserID string `json:"user_id"`\n\tData map[string]string `json:"data"`\n}\n\ntype stepOneOutput struct {\n\tMessage string `json:"message"`\n}\n\nfunc main() {\n\terr := godotenv.Load()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tch := cmdutils.InterruptChan()\n\tcleanup, err := run()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t<-ch\n\n\tif err := cleanup(); err != nil {\n\t\tpanic(fmt.Errorf("cleanup() error = %v", err))\n\t}\n}\n',
|
||||
source: 'out/go/z_v0/assignment-affinity/main.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"context"\n\t"fmt"\n\t"log"\n\t"time"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client"\n\t"github.com/hatchet-dev/hatchet/pkg/client/types"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\nfunc run() (func() error, error) {\n\tc, err := client.New()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error creating client: %w", err)\n\t}\n\n\tw, err := worker.NewWorker(\n\t\tworker.WithClient(\n\t\t\tc,\n\t\t),\n\t\tworker.WithLabels(map[string]interface{}{\n\t\t\t"model": "fancy-ai-model-v2",\n\t\t\t"memory": 1024,\n\t\t}),\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error creating worker: %w", err)\n\t}\n\n\terr = w.RegisterWorkflow(\n\t\t&worker.WorkflowJob{\n\t\t\tOn: worker.Events("user:create:affinity"),\n\t\t\tName: "affinity",\n\t\t\tDescription: "affinity",\n\t\t\tSteps: []*worker.WorkflowStep{\n\t\t\t\tworker.Fn(func(ctx worker.HatchetContext) (result *stepOneOutput, err error) {\n\n\t\t\t\t\tmodel := ctx.Worker().GetLabels()["model"]\n\n\t\t\t\t\tif model != "fancy-ai-model-v3" {\n\t\t\t\t\t\tctx.Worker().UpsertLabels(map[string]interface{}{\n\t\t\t\t\t\t\t"model": nil,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t// Do something to load the model\n\t\t\t\t\t\tctx.Worker().UpsertLabels(map[string]interface{}{\n\t\t\t\t\t\t\t"model": "fancy-ai-model-v3",\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\n\t\t\t\t\treturn &stepOneOutput{\n\t\t\t\t\t\tMessage: ctx.Worker().ID(),\n\t\t\t\t\t}, nil\n\t\t\t\t}).\n\t\t\t\t\tSetName("step-one").\n\t\t\t\t\tSetDesiredLabels(map[string]*types.DesiredWorkerLabel{\n\t\t\t\t\t\t"model": {\n\t\t\t\t\t\t\tValue: "fancy-ai-model-v3",\n\t\t\t\t\t\t\tWeight: 10,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t"memory": {\n\t\t\t\t\t\t\tValue: 512,\n\t\t\t\t\t\t\tRequired: true,\n\t\t\t\t\t\t\tComparator: types.ComparatorPtr(types.WorkerLabelComparator_GREATER_THAN),\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t},\n\t\t},\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error registering workflow: %w", err)\n\t}\n\n\tgo func() {\n\t\tlog.Printf("pushing event")\n\n\t\ttestEvent := userCreateEvent{\n\t\t\tUsername: "echo-test",\n\t\t\tUserID: "1234",\n\t\t\tData: map[string]string{\n\t\t\t\t"test": "test",\n\t\t\t},\n\t\t}\n\n\t\t// push an event\n\t\terr := c.Event().Push(\n\t\t\tcontext.Background(),\n\t\t\t"user:create:affinity",\n\t\t\ttestEvent,\n\t\t)\n\t\tif err != nil {\n\t\t\tpanic(fmt.Errorf("error pushing event: %w", err))\n\t\t}\n\n\t\ttime.Sleep(10 * time.Second)\n\t}()\n\n\tcleanup, err := w.Start()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error starting worker: %w", err)\n\t}\n\n\treturn cleanup, nil\n}\n',
|
||||
source: 'out/go/z_v0/assignment-affinity/run.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,5 +0,0 @@
|
||||
import main from './main';
|
||||
import run from './run';
|
||||
|
||||
export { main };
|
||||
export { run };
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"fmt"\n\n\t"github.com/joho/godotenv"\n\n\t"github.com/hatchet-dev/hatchet/pkg/cmdutils"\n)\n\ntype userCreateEvent struct {\n\tUsername string `json:"username"`\n\tUserID string `json:"user_id"`\n\tData map[string]string `json:"data"`\n}\n\ntype stepOneOutput struct {\n\tMessage string `json:"message"`\n}\n\nfunc main() {\n\terr := godotenv.Load()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tch := cmdutils.InterruptChan()\n\tcleanup, err := run()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t<-ch\n\n\tif err := cleanup(); err != nil {\n\t\tpanic(fmt.Errorf("cleanup() error = %v", err))\n\t}\n}\n',
|
||||
source: 'out/go/z_v0/assignment-sticky/main.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,21 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"context"\n\t"fmt"\n\t"log"\n\t"time"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client"\n\t"github.com/hatchet-dev/hatchet/pkg/client/types"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\nfunc run() (func() error, error) {\n\tc, err := client.New()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error creating client: %w", err)\n\t}\n\n\tw, err := worker.NewWorker(\n\t\tworker.WithClient(\n\t\t\tc,\n\t\t),\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error creating worker: %w", err)\n\t}\n\n\t// > StickyWorker\n\n\terr = w.RegisterWorkflow(\n\t\t&worker.WorkflowJob{\n\t\t\tOn: worker.Events("user:create:sticky"),\n\t\t\tName: "sticky",\n\t\t\tDescription: "sticky",\n\t\t\t// 👀 Specify a sticky strategy when declaring the workflow\n\t\t\tStickyStrategy: types.StickyStrategyPtr(types.StickyStrategy_HARD),\n\t\t\tSteps: []*worker.WorkflowStep{\n\t\t\t\tworker.Fn(func(ctx worker.HatchetContext) (result *stepOneOutput, err error) {\n\n\t\t\t\t\tsticky := true\n\n\t\t\t\t\t_, err = ctx.SpawnWorkflow("sticky-child", nil, &worker.SpawnWorkflowOpts{\n\t\t\t\t\t\tSticky: &sticky,\n\t\t\t\t\t})\n\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, fmt.Errorf("error spawning workflow: %w", err)\n\t\t\t\t\t}\n\n\t\t\t\t\treturn &stepOneOutput{\n\t\t\t\t\t\tMessage: ctx.Worker().ID(),\n\t\t\t\t\t}, nil\n\t\t\t\t}).SetName("step-one"),\n\t\t\t\tworker.Fn(func(ctx worker.HatchetContext) (result *stepOneOutput, err error) {\n\t\t\t\t\treturn &stepOneOutput{\n\t\t\t\t\t\tMessage: ctx.Worker().ID(),\n\t\t\t\t\t}, nil\n\t\t\t\t}).SetName("step-two").AddParents("step-one"),\n\t\t\t\tworker.Fn(func(ctx worker.HatchetContext) (result *stepOneOutput, err error) {\n\t\t\t\t\treturn &stepOneOutput{\n\t\t\t\t\t\tMessage: ctx.Worker().ID(),\n\t\t\t\t\t}, nil\n\t\t\t\t}).SetName("step-three").AddParents("step-two"),\n\t\t\t},\n\t\t},\n\t)\n\n\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error registering workflow: %w", err)\n\t}\n\n\t// > StickyChild\n\n\terr = w.RegisterWorkflow(\n\t\t&worker.WorkflowJob{\n\t\t\tOn: worker.NoTrigger(),\n\t\t\tName: "sticky-child",\n\t\t\tDescription: "sticky",\n\t\t\tSteps: []*worker.WorkflowStep{\n\t\t\t\tworker.Fn(func(ctx worker.HatchetContext) (result *stepOneOutput, err error) {\n\t\t\t\t\treturn &stepOneOutput{\n\t\t\t\t\t\tMessage: ctx.Worker().ID(),\n\t\t\t\t\t}, nil\n\t\t\t\t}).SetName("step-one"),\n\t\t\t},\n\t\t},\n\t)\n\n\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error registering workflow: %w", err)\n\t}\n\n\tgo func() {\n\t\tlog.Printf("pushing event")\n\n\t\ttestEvent := userCreateEvent{\n\t\t\tUsername: "echo-test",\n\t\t\tUserID: "1234",\n\t\t\tData: map[string]string{\n\t\t\t\t"test": "test",\n\t\t\t},\n\t\t}\n\n\t\t// push an event\n\t\terr := c.Event().Push(\n\t\t\tcontext.Background(),\n\t\t\t"user:create:sticky",\n\t\t\ttestEvent,\n\t\t)\n\t\tif err != nil {\n\t\t\tpanic(fmt.Errorf("error pushing event: %w", err))\n\t\t}\n\n\t\ttime.Sleep(10 * time.Second)\n\t}()\n\n\tcleanup, err := w.Start()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error starting worker: %w", err)\n\t}\n\n\treturn cleanup, nil\n}\n',
|
||||
source: 'out/go/z_v0/assignment-sticky/run.go',
|
||||
blocks: {
|
||||
stickyworker: {
|
||||
start: 30,
|
||||
stop: 68,
|
||||
},
|
||||
stickychild: {
|
||||
start: 75,
|
||||
stop: 90,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,3 +0,0 @@
|
||||
import main from './main';
|
||||
|
||||
export { main };
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"context"\n\t"fmt"\n\t"log"\n\n\t"github.com/joho/godotenv"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype userCreateEvent struct {\n\tUsername string `json:"username"`\n\tUserID string `json:"user_id"`\n\tData map[string]string `json:"data"`\n}\n\ntype stepOneOutput struct {\n\tMessage string `json:"message"`\n}\n\nfunc main() {\n\terr := godotenv.Load()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t_, err = run()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n}\n\nfunc run() (func() error, error) {\n\tc, err := client.New()\n\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error creating client: %w", err)\n\t}\n\n\tw, err := worker.NewWorker(\n\t\tworker.WithClient(\n\t\t\tc,\n\t\t),\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error creating worker: %w", err)\n\t}\n\n\ttestSvc := w.NewService("test")\n\n\terr = testSvc.RegisterWorkflow(\n\t\t&worker.WorkflowJob{\n\t\t\tOn: worker.Events("user:create:bulk"),\n\t\t\tName: "bulk",\n\t\t\tDescription: "This runs after an update to the user model.",\n\t\t\tSteps: []*worker.WorkflowStep{\n\t\t\t\tworker.Fn(func(ctx worker.HatchetContext) (result *stepOneOutput, err error) {\n\t\t\t\t\tinput := &userCreateEvent{}\n\n\t\t\t\t\terr = ctx.WorkflowInput(input)\n\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, err\n\t\t\t\t\t}\n\n\t\t\t\t\tlog.Printf("step-one")\n\n\t\t\t\t\treturn &stepOneOutput{\n\t\t\t\t\t\tMessage: "Username is: " + input.Username,\n\t\t\t\t\t}, nil\n\t\t\t\t},\n\t\t\t\t),\n\t\t\t},\n\t\t},\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error registering workflow: %w", err)\n\t}\n\n\tvar events []client.EventWithAdditionalMetadata\n\n\t// 20000 times to test the bulk push\n\n\tfor i := 0; i < 20000; i++ {\n\t\ttestEvent := userCreateEvent{\n\t\t\tUsername: "echo-test",\n\t\t\tUserID: "1234 " + fmt.Sprint(i),\n\t\t\tData: map[string]string{\n\t\t\t\t"test": "test " + fmt.Sprint(i),\n\t\t\t},\n\t\t}\n\t\tevents = append(events, client.EventWithAdditionalMetadata{\n\t\t\tEvent: testEvent,\n\t\t\tAdditionalMetadata: map[string]string{"hello": "world " + fmt.Sprint(i)},\n\t\t\tKey: "user:create:bulk",\n\t\t})\n\t}\n\n\tlog.Printf("pushing event user:create:bulk")\n\n\terr = c.Event().BulkPush(\n\t\tcontext.Background(),\n\t\tevents,\n\t)\n\tif err != nil {\n\t\tpanic(fmt.Errorf("error pushing event: %w", err))\n\t}\n\n\treturn nil, nil\n\n}\n',
|
||||
source: 'out/go/z_v0/bulk_imports/main.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,5 +0,0 @@
|
||||
import main from './main';
|
||||
import run from './run';
|
||||
|
||||
export { main };
|
||||
export { run };
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"fmt"\n\t"log"\n\t"time"\n\n\t"github.com/joho/godotenv"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client"\n\t"github.com/hatchet-dev/hatchet/pkg/client/types"\n\t"github.com/hatchet-dev/hatchet/pkg/cmdutils"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype userCreateEvent struct {\n\tUsername string `json:"username"`\n\tUserID string `json:"user_id"`\n\tData map[string]string `json:"data"`\n}\n\ntype stepOneOutput struct {\n\tMessage string `json:"message"`\n}\n\nfunc main() {\n\terr := godotenv.Load()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tch := cmdutils.InterruptChan()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tworkflowName := "simple-bulk-workflow"\n\tc, err := client.New()\n\n\tif err != nil {\n\t\tpanic(fmt.Errorf("error creating client: %w", err))\n\t}\n\n\t_, err = registerWorkflow(c, workflowName)\n\n\tif err != nil {\n\t\tpanic(fmt.Errorf("error registering workflow: %w", err))\n\t}\n\n\tquantity := 999\n\n\toverallStart := time.Now()\n\titerations := 10\n\tfor i := 0; i < iterations; i++ {\n\t\tstartTime := time.Now()\n\n\t\tfmt.Printf("Running the %dth bulk workflow \\n", i)\n\n\t\terr = runBulk(workflowName, quantity)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\tfmt.Printf("Time taken to queue %dth bulk workflow: %v\\n", i, time.Since(startTime))\n\t}\n\tfmt.Println("Overall time taken: ", time.Since(overallStart))\n\tfmt.Printf("That is %d workflows per second\\n", int(float64(quantity*iterations)/time.Since(overallStart).Seconds()))\n\tfmt.Println("Starting the worker")\n\n\t// err = runSingles(workflowName, quantity)\n\t// if err != nil {\n\t// \tpanic(err)\n\t// }\n\n\tif err != nil {\n\t\tpanic(fmt.Errorf("error creating client: %w", err))\n\t}\n\n\t// I want to start the wofklow worker here\n\n\tw, err := registerWorkflow(c, workflowName)\n\tif err != nil {\n\t\tpanic(fmt.Errorf("error creating worker: %w", err))\n\t}\n\n\tcleanup, err := w.Start()\n\tfmt.Println("Starting the worker")\n\n\tif err != nil {\n\t\tpanic(fmt.Errorf("error starting worker: %w", err))\n\t}\n\n\t<-ch\n\n\tif err := cleanup(); err != nil {\n\t\tpanic(fmt.Errorf("error cleaning up: %w", err))\n\t}\n\n}\n\nfunc getConcurrencyKey(ctx worker.HatchetContext) (string, error) {\n\treturn "my-key", nil\n}\n\nfunc registerWorkflow(c client.Client, workflowName string) (w *worker.Worker, err error) {\n\n\tw, err = worker.NewWorker(\n\t\tworker.WithClient(\n\t\t\tc,\n\t\t),\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error creating worker: %w", err)\n\t}\n\n\terr = w.RegisterWorkflow(\n\t\t&worker.WorkflowJob{\n\t\t\tOn: worker.Events("user:create:bulk-simple"),\n\t\t\tName: workflowName,\n\t\t\tConcurrency: worker.Concurrency(getConcurrencyKey).MaxRuns(200).LimitStrategy(types.GroupRoundRobin),\n\t\t\tDescription: "This runs after an update to the user model.",\n\t\t\tSteps: []*worker.WorkflowStep{\n\t\t\t\tworker.Fn(func(ctx worker.HatchetContext) (result *stepOneOutput, err error) {\n\t\t\t\t\tinput := &userCreateEvent{}\n\n\t\t\t\t\terr = ctx.WorkflowInput(input)\n\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, err\n\t\t\t\t\t}\n\n\t\t\t\t\tlog.Printf("step-one")\n\n\t\t\t\t\treturn &stepOneOutput{\n\t\t\t\t\t\tMessage: "Username is: " + input.Username,\n\t\t\t\t\t}, nil\n\t\t\t\t},\n\t\t\t\t).SetName("step-one"),\n\t\t\t\tworker.Fn(func(ctx worker.HatchetContext) (result *stepOneOutput, err error) {\n\t\t\t\t\tinput := &stepOneOutput{}\n\t\t\t\t\terr = ctx.StepOutput("step-one", input)\n\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, err\n\t\t\t\t\t}\n\n\t\t\t\t\tlog.Printf("step-two")\n\n\t\t\t\t\treturn &stepOneOutput{\n\t\t\t\t\t\tMessage: "Above message is: " + input.Message,\n\t\t\t\t\t}, nil\n\t\t\t\t}).SetName("step-two").AddParents("step-one"),\n\t\t\t},\n\t\t},\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error registering workflow: %w", err)\n\t}\n\treturn w, nil\n}\n',
|
||||
source: 'out/go/z_v0/bulk_workflows/main.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"fmt"\n\t"log"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client"\n)\n\nfunc runBulk(workflowName string, quantity int) error {\n\tc, err := client.New()\n\tif err != nil {\n\t\treturn fmt.Errorf("error creating client: %w", err)\n\t}\n\n\tlog.Printf("pushing %d workflows in bulk", quantity)\n\n\tvar workflows []*client.WorkflowRun\n\tfor i := 0; i < quantity; i++ {\n\t\tdata := map[string]interface{}{\n\t\t\t"username": fmt.Sprintf("echo-test-%d", i),\n\t\t\t"user_id": fmt.Sprintf("1234-%d", i),\n\t\t}\n\t\tworkflows = append(workflows, &client.WorkflowRun{\n\t\t\tName: workflowName,\n\t\t\tInput: data,\n\t\t\tOptions: []client.RunOptFunc{\n\t\t\t\t// setting a dedupe key so these shouldn\'t all run\n\t\t\t\tclient.WithRunMetadata(map[string]interface{}{\n\t\t\t\t\t// "dedupe": "dedupe1",\n\t\t\t\t}),\n\t\t\t},\n\t\t})\n\n\t}\n\n\touts, err := c.Admin().BulkRunWorkflow(workflows)\n\tif err != nil {\n\t\tpanic(fmt.Errorf("error pushing event: %w", err))\n\t}\n\n\tfor _, out := range outs {\n\t\tlog.Printf("workflow run id: %v", out)\n\t}\n\n\treturn nil\n\n}\n\nfunc runSingles(workflowName string, quantity int) error {\n\tc, err := client.New()\n\tif err != nil {\n\t\treturn fmt.Errorf("error creating client: %w", err)\n\t}\n\n\tlog.Printf("pushing %d single workflows", quantity)\n\n\tvar workflows []*client.WorkflowRun\n\tfor i := 0; i < quantity; i++ {\n\t\tdata := map[string]interface{}{\n\t\t\t"username": fmt.Sprintf("echo-test-%d", i),\n\t\t\t"user_id": fmt.Sprintf("1234-%d", i),\n\t\t}\n\t\tworkflows = append(workflows, &client.WorkflowRun{\n\t\t\tName: workflowName,\n\t\t\tInput: data,\n\t\t\tOptions: []client.RunOptFunc{\n\t\t\t\tclient.WithRunMetadata(map[string]interface{}{\n\t\t\t\t\t// "dedupe": "dedupe1",\n\t\t\t\t}),\n\t\t\t},\n\t\t})\n\t}\n\n\tfor _, wf := range workflows {\n\n\t\tgo func() {\n\t\t\tout, err := c.Admin().RunWorkflow(wf.Name, wf.Input, wf.Options...)\n\t\t\tif err != nil {\n\t\t\t\tpanic(fmt.Errorf("error pushing event: %w", err))\n\t\t\t}\n\n\t\t\tlog.Printf("workflow run id: %v", out)\n\t\t}()\n\n\t}\n\n\treturn nil\n}\n',
|
||||
source: 'out/go/z_v0/bulk_workflows/run.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,5 +0,0 @@
|
||||
import main from './main';
|
||||
import run from './run';
|
||||
|
||||
export { main };
|
||||
export { run };
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"fmt"\n\n\t"github.com/joho/godotenv"\n\n\t"github.com/hatchet-dev/hatchet/pkg/cmdutils"\n)\n\ntype userCreateEvent struct {\n\tUsername string `json:"username"`\n\tUserID string `json:"user_id"`\n\tData map[string]string `json:"data"`\n}\n\ntype stepOneOutput struct {\n\tMessage string `json:"message"`\n}\n\nfunc main() {\n\terr := godotenv.Load()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tevents := make(chan string, 50)\n\tch := cmdutils.InterruptChan()\n\tcleanup, err := run(events)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t<-ch\n\n\tif err := cleanup(); err != nil {\n\t\tpanic(fmt.Errorf("cleanup() error = %v", err))\n\t}\n}\n',
|
||||
source: 'out/go/z_v0/cancellation/main.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"context"\n\t"fmt"\n\t"log"\n\t"time"\n\n\t"github.com/google/uuid"\n\t"github.com/hatchet-dev/hatchet/pkg/client"\n\t"github.com/hatchet-dev/hatchet/pkg/client/rest"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\nfunc run(events chan<- string) (func() error, error) {\n\tc, err := client.New()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error creating client: %w", err)\n\t}\n\n\tw, err := worker.NewWorker(\n\t\tworker.WithClient(\n\t\t\tc,\n\t\t),\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error creating worker: %w", err)\n\t}\n\n\terr = w.RegisterWorkflow(\n\t\t&worker.WorkflowJob{\n\t\t\tOn: worker.Events("user:create:cancellation"),\n\t\t\tName: "cancellation",\n\t\t\tDescription: "cancellation",\n\t\t\tSteps: []*worker.WorkflowStep{\n\t\t\t\tworker.Fn(func(ctx worker.HatchetContext) (result *stepOneOutput, err error) {\n\t\t\t\t\tselect {\n\t\t\t\t\tcase <-ctx.Done():\n\t\t\t\t\t\tevents <- "done"\n\t\t\t\t\t\tlog.Printf("context cancelled")\n\t\t\t\t\t\treturn nil, nil\n\t\t\t\t\tcase <-time.After(30 * time.Second):\n\t\t\t\t\t\tlog.Printf("workflow never cancelled")\n\t\t\t\t\t\treturn &stepOneOutput{\n\t\t\t\t\t\t\tMessage: "done",\n\t\t\t\t\t\t}, nil\n\t\t\t\t\t}\n\t\t\t\t}).SetName("step-one"),\n\t\t\t},\n\t\t},\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error registering workflow: %w", err)\n\t}\n\n\tgo func() {\n\t\tlog.Printf("pushing event")\n\n\t\ttestEvent := userCreateEvent{\n\t\t\tUsername: "echo-test",\n\t\t\tUserID: "1234",\n\t\t\tData: map[string]string{\n\t\t\t\t"test": "test",\n\t\t\t},\n\t\t}\n\n\t\t// push an event\n\t\terr := c.Event().Push(\n\t\t\tcontext.Background(),\n\t\t\t"user:create:cancellation",\n\t\t\ttestEvent,\n\t\t)\n\t\tif err != nil {\n\t\t\tpanic(fmt.Errorf("error pushing event: %w", err))\n\t\t}\n\n\t\ttime.Sleep(10 * time.Second)\n\n\t\tworkflowName := "cancellation"\n\n\t\tworkflows, err := c.API().WorkflowListWithResponse(context.Background(), uuid.MustParse(c.TenantId()), &rest.WorkflowListParams{\n\t\t\tName: &workflowName,\n\t\t})\n\n\t\tif err != nil {\n\t\t\tpanic(fmt.Errorf("error listing workflows: %w", err))\n\t\t}\n\n\t\tif workflows.JSON200 == nil {\n\t\t\tpanic(fmt.Errorf("no workflows found"))\n\t\t}\n\n\t\trows := *workflows.JSON200.Rows\n\n\t\tif len(rows) == 0 {\n\t\t\tpanic(fmt.Errorf("no workflows found"))\n\t\t}\n\n\t\tworkflowId := uuid.MustParse(rows[0].Metadata.Id)\n\n\t\tworkflowRuns, err := c.API().WorkflowRunListWithResponse(context.Background(), uuid.MustParse(c.TenantId()), &rest.WorkflowRunListParams{\n\t\t\tWorkflowId: &workflowId,\n\t\t})\n\n\t\tif err != nil {\n\t\t\tpanic(fmt.Errorf("error listing workflow runs: %w", err))\n\t\t}\n\n\t\tif workflowRuns.JSON200 == nil {\n\t\t\tpanic(fmt.Errorf("no workflow runs found"))\n\t\t}\n\n\t\tworkflowRunsRows := *workflowRuns.JSON200.Rows\n\n\t\t_, err = c.API().WorkflowRunCancelWithResponse(context.Background(), uuid.MustParse(c.TenantId()), rest.WorkflowRunsCancelRequest{\n\t\t\tWorkflowRunIds: []uuid.UUID{uuid.MustParse(workflowRunsRows[0].Metadata.Id)},\n\t\t})\n\n\t\tif err != nil {\n\t\t\tpanic(fmt.Errorf("error cancelling workflow run: %w", err))\n\t\t}\n\t}()\n\n\tcleanup, err := w.Start()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error starting worker: %w", err)\n\t}\n\n\treturn cleanup, nil\n}\n',
|
||||
source: 'out/go/z_v0/cancellation/run.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,3 +0,0 @@
|
||||
import main from './main';
|
||||
|
||||
export { main };
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"context"\n\t"fmt"\n\t"log"\n\n\t"github.com/joho/godotenv"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client"\n\t"github.com/hatchet-dev/hatchet/pkg/client/compute"\n\t"github.com/hatchet-dev/hatchet/pkg/cmdutils"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype userCreateEvent struct {\n\tUsername string `json:"username"`\n\tUserID string `json:"user_id"`\n\tData map[string]string `json:"data"`\n}\n\ntype stepOneOutput struct {\n\tMessage string `json:"message"`\n}\n\nfunc main() {\n\terr := godotenv.Load()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tevents := make(chan string, 50)\n\tinterrupt := cmdutils.InterruptChan()\n\n\tcleanup, err := run(events)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t<-interrupt\n\n\tif err := cleanup(); err != nil {\n\t\tpanic(fmt.Errorf("error cleaning up: %w", err))\n\t}\n}\n\nfunc run(events chan<- string) (func() error, error) {\n\tc, err := client.New()\n\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error creating client: %w", err)\n\t}\n\n\tw, err := worker.NewWorker(\n\t\tworker.WithClient(\n\t\t\tc,\n\t\t),\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error creating worker: %w", err)\n\t}\n\n\tpool := "test-pool"\n\tbasicCompute := compute.Compute{\n\t\tPool: &pool,\n\t\tNumReplicas: 1,\n\t\tCPUs: 1,\n\t\tMemoryMB: 1024,\n\t\tCPUKind: compute.ComputeKindSharedCPU,\n\t\tRegions: []compute.Region{compute.Region("ewr")},\n\t}\n\n\tperformancePool := "performance-pool"\n\tperformanceCompute := compute.Compute{\n\t\tPool: &performancePool,\n\t\tNumReplicas: 1,\n\t\tCPUs: 2,\n\t\tMemoryMB: 1024,\n\t\tCPUKind: compute.ComputeKindPerformanceCPU,\n\t\tRegions: []compute.Region{compute.Region("ewr")},\n\t}\n\n\terr = w.RegisterWorkflow(\n\t\t&worker.WorkflowJob{\n\t\t\tOn: worker.Events("user:create:simple"),\n\t\t\tName: "simple",\n\t\t\tDescription: "This runs after an update to the user model.",\n\t\t\tConcurrency: worker.Expression("input.user_id"),\n\t\t\tSteps: []*worker.WorkflowStep{\n\t\t\t\tworker.Fn(func(ctx worker.HatchetContext) (result *stepOneOutput, err error) {\n\t\t\t\t\tinput := &userCreateEvent{}\n\n\t\t\t\t\terr = ctx.WorkflowInput(input)\n\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, err\n\t\t\t\t\t}\n\n\t\t\t\t\tlog.Printf("step-one")\n\t\t\t\t\tevents <- "step-one"\n\n\t\t\t\t\treturn &stepOneOutput{\n\t\t\t\t\t\tMessage: "Username is: " + input.Username,\n\t\t\t\t\t}, nil\n\t\t\t\t},\n\t\t\t\t).SetName("step-one").SetCompute(&basicCompute),\n\t\t\t\tworker.Fn(func(ctx worker.HatchetContext) (result *stepOneOutput, err error) {\n\t\t\t\t\tinput := &stepOneOutput{}\n\t\t\t\t\terr = ctx.StepOutput("step-one", input)\n\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, err\n\t\t\t\t\t}\n\n\t\t\t\t\tlog.Printf("step-two")\n\t\t\t\t\tevents <- "step-two"\n\n\t\t\t\t\treturn &stepOneOutput{\n\t\t\t\t\t\tMessage: "Above message is: " + input.Message,\n\t\t\t\t\t}, nil\n\t\t\t\t}).SetName("step-two").AddParents("step-one").SetCompute(&performanceCompute),\n\t\t\t},\n\t\t},\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error registering workflow: %w", err)\n\t}\n\n\tgo func() {\n\t\ttestEvent := userCreateEvent{\n\t\t\tUsername: "echo-test",\n\t\t\tUserID: "1234",\n\t\t\tData: map[string]string{\n\t\t\t\t"test": "test",\n\t\t\t},\n\t\t}\n\n\t\tlog.Printf("pushing event user:create:simple")\n\t\t// push an event\n\t\terr := c.Event().Push(\n\t\t\tcontext.Background(),\n\t\t\t"user:create:simple",\n\t\t\ttestEvent,\n\t\t\tclient.WithEventMetadata(map[string]string{\n\t\t\t\t"hello": "world",\n\t\t\t}),\n\t\t)\n\t\tif err != nil {\n\t\t\tpanic(fmt.Errorf("error pushing event: %w", err))\n\t\t}\n\t}()\n\n\tcleanup, err := w.Start()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\treturn cleanup, nil\n}\n',
|
||||
source: 'out/go/z_v0/compute/main.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,3 +0,0 @@
|
||||
import main from './main';
|
||||
|
||||
export { main };
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"fmt"\n\t"log"\n\t"time"\n\n\t"github.com/joho/godotenv"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client"\n\t"github.com/hatchet-dev/hatchet/pkg/client/types"\n\t"github.com/hatchet-dev/hatchet/pkg/cmdutils"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\ntype userCreateEvent struct {\n\tUsername string `json:"username"`\n\tUserID string `json:"user_id"`\n\tData map[string]string `json:"data"`\n}\n\ntype stepOneOutput struct {\n\tMessage string `json:"message"`\n}\n\nfunc main() {\n\terr := godotenv.Load()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tevents := make(chan string, 50)\n\tinterrupt := cmdutils.InterruptChan()\n\n\tcleanup, err := run(events)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t<-interrupt\n\n\tif err := cleanup(); err != nil {\n\n\t\tpanic(fmt.Errorf("error cleaning up: %w", err))\n\t}\n}\n\nfunc run(events chan<- string) (func() error, error) {\n\tc, err := client.New()\n\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error creating client: %w", err)\n\t}\n\n\tw, err := worker.NewWorker(\n\t\tworker.WithClient(\n\t\t\tc,\n\t\t),\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error creating worker: %w", err)\n\t}\n\n\terr = w.RegisterWorkflow(\n\t\t&worker.WorkflowJob{\n\t\t\tOn: worker.Events("user:create:concurrency"),\n\t\t\tName: "simple-concurrency",\n\t\t\tDescription: "This runs to test concurrency.",\n\t\t\tConcurrency: worker.Expression("\'concurrency\'").MaxRuns(1).LimitStrategy(types.GroupRoundRobin),\n\t\t\tSteps: []*worker.WorkflowStep{\n\t\t\t\tworker.Fn(func(ctx worker.HatchetContext) (result *stepOneOutput, err error) {\n\t\t\t\t\tinput := &userCreateEvent{}\n\n\t\t\t\t\terr = ctx.WorkflowInput(input)\n\n\t\t\t\t\t// we sleep to simulate a long running task\n\t\t\t\t\ttime.Sleep(10 * time.Second)\n\n\t\t\t\t\tif err != nil {\n\n\t\t\t\t\t\treturn nil, err\n\t\t\t\t\t}\n\n\t\t\t\t\tif ctx.Err() != nil {\n\t\t\t\t\t\treturn nil, ctx.Err()\n\t\t\t\t\t}\n\n\t\t\t\t\tlog.Printf("step-one")\n\t\t\t\t\tevents <- "step-one"\n\n\t\t\t\t\treturn &stepOneOutput{\n\t\t\t\t\t\tMessage: "Username is: " + input.Username,\n\t\t\t\t\t}, nil\n\t\t\t\t},\n\t\t\t\t).SetName("step-one"),\n\t\t\t\tworker.Fn(func(ctx worker.HatchetContext) (result *stepOneOutput, err error) {\n\t\t\t\t\tinput := &stepOneOutput{}\n\t\t\t\t\terr = ctx.StepOutput("step-one", input)\n\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, err\n\t\t\t\t\t}\n\n\t\t\t\t\tif ctx.Err() != nil {\n\t\t\t\t\t\treturn nil, ctx.Err()\n\t\t\t\t\t}\n\n\t\t\t\t\tlog.Printf("step-two")\n\t\t\t\t\tevents <- "step-two"\n\n\t\t\t\t\treturn &stepOneOutput{\n\t\t\t\t\t\tMessage: "Above message is: " + input.Message,\n\t\t\t\t\t}, nil\n\t\t\t\t}).SetName("step-two").AddParents("step-one"),\n\t\t\t},\n\t\t},\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf("error registering workflow: %w", err)\n\t}\n\ttestEvent := userCreateEvent{\n\t\tUsername: "echo-test",\n\t\tUserID: "1234",\n\t\tData: map[string]string{\n\t\t\t"test": "test",\n\t\t},\n\t}\n\tgo func() {\n\t\t// do this 10 times to test concurrency\n\t\tfor i := 0; i < 10; i++ {\n\n\t\t\twfr_id, err := c.Admin().RunWorkflow("simple-concurrency", testEvent)\n\n\t\t\tlog.Println("Starting workflow run id: ", wfr_id)\n\n\t\t\tif err != nil {\n\t\t\t\tpanic(fmt.Errorf("error running workflow: %w", err))\n\t\t\t}\n\n\t\t}\n\t}()\n\n\tcleanup, err := w.Start()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\treturn cleanup, nil\n}\n',
|
||||
source: 'out/go/z_v0/concurrency/main.go',
|
||||
blocks: {},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,3 +0,0 @@
|
||||
import main from './main';
|
||||
|
||||
export { main };
|
||||
@@ -1,25 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/joho/godotenv"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client"\n\t"github.com/hatchet-dev/hatchet/pkg/cmdutils"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\n// > Create\n// ... normal workflow definition\ntype printOutput struct{}\n\nfunc print(ctx context.Context) (result *printOutput, err error) {\n\tfmt.Println("called print:print")\n\n\treturn &printOutput{}, nil\n}\n\n// ,\nfunc main() {\n\t// ... initialize client, worker and workflow\n\terr := godotenv.Load()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tc, err := client.New()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tw, err := worker.NewWorker(\n\t\tworker.WithClient(\n\t\t\tc,\n\t\t),\n\t)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\terr = w.RegisterWorkflow(\n\t\t&worker.WorkflowJob{\n\t\t\tOn: worker.NoTrigger(),\n\t\t\tName: "cron-workflow",\n\t\t\tDescription: "Demonstrates a simple cron workflow",\n\t\t\tSteps: []*worker.WorkflowStep{\n\t\t\t\tworker.Fn(print),\n\t\t\t},\n\t\t},\n\t)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tinterrupt := cmdutils.InterruptChan()\n\n\tcleanup, err := w.Start()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// ,\n\n\tgo func() {\n\t\t// 👀 define the cron expression to run every minute\n\t\tcron, err := c.Cron().Create(\n\t\t\tcontext.Background(),\n\t\t\t"cron-workflow",\n\t\t\t&client.CronOpts{\n\t\t\t\tName: "every-minute",\n\t\t\t\tExpression: "* * * * *",\n\t\t\t\tInput: map[string]interface{}{\n\t\t\t\t\t"message": "Hello, world!",\n\t\t\t\t},\n\t\t\t\tAdditionalMetadata: map[string]string{},\n\t\t\t},\n\t\t)\n\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\n\t\tfmt.Println(*cron.Name, cron.Cron)\n\t}()\n\n\t// ... wait for interrupt signal\n\n\t<-interrupt\n\n\tif err := cleanup(); err != nil {\n\t\tpanic(fmt.Errorf("error cleaning up: %w", err))\n\t}\n\n\t// ,\n}\n\n\nfunc ListCrons() {\n\n\tc, err := client.New()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// > List\n\tcrons, err := c.Cron().List(context.Background())\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfor _, cron := range *crons.Rows {\n\t\tfmt.Println(cron.Cron, *cron.Name)\n\t}\n}\n\nfunc DeleteCron(id string) {\n\tc, err := client.New()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// > Delete\n\t// 👀 id is the cron\'s metadata id, can get it via cron.Metadata.Id\n\terr = c.Cron().Delete(context.Background(), id)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n}\n',
|
||||
source: 'out/go/z_v0/cron-programmatic/main.go',
|
||||
blocks: {
|
||||
create: {
|
||||
start: 15,
|
||||
stop: 106,
|
||||
},
|
||||
list: {
|
||||
start: 117,
|
||||
stop: 117,
|
||||
},
|
||||
delete: {
|
||||
start: 136,
|
||||
stop: 137,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,3 +0,0 @@
|
||||
import main from './main';
|
||||
|
||||
export { main };
|
||||
@@ -1,17 +0,0 @@
|
||||
import { Snippet } from '@/next/lib/docs/generated/snips/types';
|
||||
|
||||
const snippet: Snippet = {
|
||||
language: 'go',
|
||||
content:
|
||||
'package main\n\nimport (\n\t"context"\n\t"fmt"\n\n\t"github.com/joho/godotenv"\n\n\t"github.com/hatchet-dev/hatchet/pkg/client"\n\t"github.com/hatchet-dev/hatchet/pkg/cmdutils"\n\t"github.com/hatchet-dev/hatchet/pkg/worker"\n)\n\n// > Workflow Definition Cron Trigger\n// ... normal workflow definition\ntype printOutput struct{}\n\nfunc print(ctx context.Context) (result *printOutput, err error) {\n\tfmt.Println("called print:print")\n\n\treturn &printOutput{}, nil\n}\n\n// ,\nfunc main() {\n\t// ... initialize client and worker\n\terr := godotenv.Load()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tclient, err := client.New()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tw, err := worker.NewWorker(\n\t\tworker.WithClient(\n\t\t\tclient,\n\t\t),\n\t)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// ,\n\terr = w.RegisterWorkflow(\n\t\t&worker.WorkflowJob{\n\t\t\t// 👀 define the cron expression to run every minute\n\t\t\tOn: worker.Cron("* * * * *"),\n\t\t\tName: "cron-workflow",\n\t\t\tDescription: "Demonstrates a simple cron workflow",\n\t\t\tSteps: []*worker.WorkflowStep{\n\t\t\t\tworker.Fn(print),\n\t\t\t},\n\t\t},\n\t)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// ... start worker\n\n\tinterrupt := cmdutils.InterruptChan()\n\n\tcleanup, err := w.Start()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t<-interrupt\n\n\tif err := cleanup(); err != nil {\n\t\tpanic(fmt.Errorf("error cleaning up: %w", err))\n\t}\n\n\t// ,\n}\n\n',
|
||||
source: 'out/go/z_v0/cron/main.go',
|
||||
blocks: {
|
||||
workflow_definition_cron_trigger: {
|
||||
start: 15,
|
||||
stop: 84,
|
||||
},
|
||||
},
|
||||
highlights: {},
|
||||
};
|
||||
|
||||
export default snippet;
|
||||
@@ -1,3 +0,0 @@
|
||||
import main from './main';
|
||||
|
||||
export { main };
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user