Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert supported workflows and activities from actions to config #10

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ deployment, follow the following steps:
# Attach wheel file resource:
juju attach-resource temporal-worker-k8s workflows-file=./resource_sample/dist/python_samples-1.1.0-py3-none-any.whl

# Add supported workflow and activity:
juju run temporal-worker-k8s/0 add-workflows workflows="GreetingWorkflow"
juju run temporal-worker-k8s/0 add-activities activities="compose_greeting"

# Check progress:
juju status --relations --watch 1s
juju debug-log
Expand Down
20 changes: 5 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ temporal-worker-k8s:
queue: "test-queue"
namespace: "test"
workflows-file-name: "python_samples-1.1.0-py3-none-any.whl"
# To support all defined workflows and activities, use the 'all' keyword
supported-workflows: "all"
supported-activities: "all"
```

### Attaching "workflows-file" resource
Expand Down Expand Up @@ -65,21 +68,6 @@ Once ready, the resource can be attached as follows:
juju attach-resource temporal-worker-k8s workflows-file=./resource_sample/dist/python_samples-1.1.0-py3-none-any.whl
```

### Defining supported workflows and activities

Once the wheel file is processed by the worker to extract all the workflows and
activities, a list of supported workflows and activities must be defined by the
user before the charm can be started. This can be done as follows:

```bash
juju run temporal-worker-k8s/0 add-workflows workflows="GreetingWorkflow"
juju run temporal-worker-k8s/0 add-activities activities="compose_greeting"

# To support all defined workflows and activities, use the 'all' keyword
juju run temporal-worker-k8s/0 add-workflows workflows="all"
juju run temporal-worker-k8s/0 add-activities activities="all"
```

Once done, the charm should enter an active state, indicating that the worker is
running successfully. To verify this, you can check the logs of the kubernetes
pod to ensure there are no errors with the workload container:
Expand Down Expand Up @@ -120,6 +108,8 @@ following command:

```bash
juju config temporal-worker-k8s sentry-dsn=<YOUR_SENTRY_DSN>
juju config temporal-worker-k8s sentry-release="1.0.0"
juju config temporal-worker-k8s sentry-environment="staging"
```

## Contributing
Expand Down
48 changes: 0 additions & 48 deletions actions.yaml
Original file line number Diff line number Diff line change
@@ -1,53 +1,5 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

add-workflows:
description: |
Add to the list of workflows supported by worker. This can either be
done by specifying class names of the Temporal workflow definitions
(marked by @workflow.defn), or using the keyword "all" to include
all classes inside the "workflows" directory.

params:
workflows:
type: string
description: comma-separated list of workflow names.
required: [workflows]

remove-workflows:
description: Remove from the list of workflows supported by worker.
params:
workflows:
type: string
description: comma-separated list of workflow names.
required: [workflows]

list-workflows:
description: Return list of workflows supported by worker.

add-activities:
description: |
Add to the list of activities supported by worker. This can either be
done by specifying method names of the Temporal activity definitions
(marked by @activity.defn), or using the keyword "all" to include
all methods inside the "activities" directory.

params:
activities:
type: string
description: comma-separated list of activity names.
required: [activities]

remove-activities:
description: Remove from the list of activities supported by worker.
params:
activities:
type: string
description: comma-separated list of activity names.
required: [activities]

list-activities:
description: Return list of activities supported by worker.

restart:
description: Restart the Temporal worker.
10 changes: 10 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ options:
default: ""
type: string

supported-workflows:
description: Comma-separated list of workflow names to extract from attached wheel file.
default: ""
type: string

supported-activities:
description: Comma-separated list of workflow activities to extract from attached wheel file.
default: ""
type: string

sentry-dsn:
description: Sentry Data Source Name to send events to.
default: ""
Expand Down
3 changes: 0 additions & 3 deletions src/actions/__init__.py

This file was deleted.

96 changes: 0 additions & 96 deletions src/actions/activities.py

This file was deleted.

91 changes: 0 additions & 91 deletions src/actions/workflows.py

This file was deleted.

21 changes: 1 addition & 20 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
WaitingStatus,
)

from actions.activities import ActivitiesActions
from actions.workflows import WorkflowsActions
from literals import (
REQUIRED_CANDID_CONFIG,
REQUIRED_CHARM_CONFIG,
Expand Down Expand Up @@ -56,9 +54,6 @@ def __init__(self, *args):
self.framework.observe(self.on.temporal_worker_pebble_ready, self._on_temporal_worker_pebble_ready)
self.framework.observe(self.on.restart_action, self._on_restart)

self.workflows_actions = WorkflowsActions(self)
self.activities_actions = ActivitiesActions(self)

@log_event_handler(logger)
def _on_temporal_worker_pebble_ready(self, event):
"""Define and start temporal using the Pebble API.
Expand All @@ -70,12 +65,6 @@ def _on_temporal_worker_pebble_ready(self, event):
event.defer()
return

if self.unit.is_leader():
if self._state.supported_workflows is None:
self._state.supported_workflows = []
if self._state.supported_activities is None:
self._state.supported_activities = []

self._update(event)

@log_event_handler(logger)
Expand Down Expand Up @@ -257,12 +246,6 @@ def _validate(self, event): # noqa: C901

self._check_required_config(REQUIRED_CHARM_CONFIG)

if self._state.supported_workflows is None or len(self._state.supported_workflows) == 0:
raise ValueError("Invalid state: must have at least one supported workflow")

if self._state.supported_activities is None or len(self._state.supported_activities) == 0:
raise ValueError("Invalid state: must have at least one supported activity")

if self._state.module_name is None:
raise ValueError("Invalid state: error extracting folder name from wheel file")

Expand Down Expand Up @@ -302,9 +285,7 @@ def _update(self, event):
logger.info("Configuring Temporal worker")

module_name = self._state.module_name
sw = self._state.supported_workflows
sa = self._state.supported_activities
command = f"python worker.py '{json.dumps(dict(self.config))}' '{','.join(sw)}' '{','.join(sa)}' {module_name}"
command = f"python worker.py '{json.dumps(dict(self.config))}' {module_name}"

pebble_layer = {
"summary": "temporal worker layer",
Expand Down
2 changes: 1 addition & 1 deletion src/literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""Literals used by the Temporal Worker K8s charm."""

VALID_LOG_LEVELS = ["info", "debug", "warning", "error", "critical"]
REQUIRED_CHARM_CONFIG = ["host", "namespace", "queue"]
REQUIRED_CHARM_CONFIG = ["host", "namespace", "queue", "supported-workflows", "supported-activities"]
REQUIRED_CANDID_CONFIG = ["candid-url", "candid-username", "candid-public-key", "candid-private-key"]
REQUIRED_OIDC_CONFIG = [
"oidc-auth-type",
Expand Down
Loading
Loading