Skip to content

Commit

Permalink
more cleanup and mention js sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
c4lm committed Dec 21, 2023
1 parent 9d58416 commit 235b5c1
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 138 deletions.
55 changes: 1 addition & 54 deletions docs/devguide/how-tos/Workers/build-a-golang-task-worker.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,3 @@
# Build a Go Task Worker

## Install
```shell
go get github.com/netflix/conductor/client/go
```
This will create a Go project under $GOPATH/src and download any dependencies.

## Implementing a Task a Worker
`task`package provies the types used to implement the worker. Here is a reference worker implementation:

```go
package task

import (
"fmt"
)

// Implementation for "task_1"
func Task_1_Execution_Function(t *task.Task) (taskResult *task.TaskResult, err error) {
log.Println("Executing Task_1_Execution_Function for", t.TaskType)

//Do some logic
taskResult = task.NewTaskResult(t)

output := map[string]interface{}{"task":"task_1", "key2":"value2", "key3":3, "key4":false}
taskResult.OutputData = output
taskResult.Status = "COMPLETED"
err = nil

return taskResult, err
}
```

## Worker Polling
Here is an example that shows how to start polling for tasks after defining the tasks.

```go
package main

import (
"github.com/netflix/conductor/client/go"
"github.com/netflix/conductor/client/go/task/sample"
)

func main() {
c := conductor.NewConductorWorker("{{ server_host }}", 1, 10000)

c.Start("task_1", "", sample.Task_1_Execution_Function, false)
c.Start("task_2", "mydomain", sample.Task_2_Execution_Function, true)
}
```
### `NewConductorWoker` parameters
1. baseUrl: Server address.
2. threadCount: No. of threads. Number of threads should be at-least same as the number of workers
3. pollingInterval: Time in millisecond between subsequent polls
See [conductor-sdk/conductor-go](https://github.com/conductor-sdk/conductor-go/blob/main/README.md)
80 changes: 1 addition & 79 deletions docs/devguide/how-tos/Workers/build-a-python-task-worker.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,4 @@
# Build a Python Task Worker
## Install the python client
```shell
virtualenv conductorclient
source conductorclient/bin/activate
cd ../conductor/client/python
python setup.py install
```

## Implement a Task Worker
[ConductorWorker](https://github.com/Netflix/conductor/blob/main/polyglot-clients/python/conductor/ConductorWorker.py#L36)
class is used to implement task workers.
The following script shows how to bring up two task workers named `book_flight` and `book_car`:

```python
from __future__ import print_function
from conductor.ConductorWorker import ConductorWorker

def book_flight_task(task):
return {'status': 'COMPLETED', 'output': {'booking_ref': 2341111, 'airline': 'delta'}, 'logs': ['trying delta', 'skipping aa']}

def book_car_task(task):
return {'status': 'COMPLETED', 'output': {'booking_ref': "84545fdfd", 'agency': 'hertz'}, 'logs': ['trying hertz']}

def main():
print('Starting Travel Booking workflows')
cc = ConductorWorker('{{ server_host }}{{ api_prefix }}', 1, 0.1)
cc.start('book_flight', book_flight_task, False)
cc.start('book_car', book_car_task, True)

if __name__ == '__main__':
main()
```
### `ConductorWorker` parameters
```python
server_url: str
The url to the server hosting the conductor api.
Ex: '{{ server_host }}{{ api_prefix }}'

thread_count: int
The number of threads that will be polling for and
executing tasks in case of using the start method.

polling_interval: float
The number of seconds that each worker thread will wait
between polls to the conductor server.

worker_id: str, optional
The worker_id of the worker that is going to execute the
task. For further details, refer to the documentation
By default, it is set to hostname of the machine
```
### `start` method parameters
```pythhon
taskType: str
The name of the task that the worker is looking to execute
exec_function: function
The function that the worker will execute. The function
must return a dict with the `status`, `output` and `logs`
keys present. If this is not present, an Exception will be
raised
wait: bool
Whether the worker will block execution of further code.
Since the workers are being run in daemon threads, when the
program completes execution, all the threads are destroyed.
Setting wait to True prevents the program from ending.
If multiple workers are being called from the same program,
all but the last start call but have wait set to False.
The last start call must always set wait to True. If a
single worker is being called, set wait to True.
domain: str, optional
The domain of the task under which the worker will run. For
further details refer to the conductor server documentation
By default, it is set to None
```

See
[https://github.com/Netflix/conductor/tree/main/polyglot-clients/python](https://github.com/Netflix/conductor/tree/main/polyglot-clients/python)
for the source code.
[conductor-sdk/conductor-python](https://github.com/conductor-sdk/conductor-python/blob/main/README.md)
2 changes: 1 addition & 1 deletion docs/devguide/running/docker.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Running Conductor Using Docker

In this article we will explore how you can set up Netflix Conductor on your local machine using Docker compose.
In this article we will explore how you can set up Conductor on your local machine using Docker compose.
The docker compose will bring up the following:

1. Conductor API Server
Expand Down
4 changes: 0 additions & 4 deletions docs/documentation/advanced/azureblob-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ It has only been tested with **v12.2.0**.

## Configuration

### Usage

Cf. Documentation [External Payload Storage](https://netflix.github.io/conductor/externalpayloadstorage/#azure-blob-storage)

### Example

```properties
Expand Down
1 change: 1 addition & 0 deletions docs/documentation/clientsdks/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ Conductor tasks that are executed by remote workers communicate over HTTP endpoi
* [C#](csharp-sdk.md)
* [Go](go-sdk.md)
* [Python](python-sdk.md)
* [Javascript/Typescript](js-sdk.md)

The non-Java Conductor SDKs are hosted on a separate GitHub repository: [github.com/conductor-sdk](https://github.com/conductor-sdk). Contributions from the community are encouraged!
3 changes: 3 additions & 0 deletions docs/documentation/clientsdks/js-sdk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Javascript/TypeScript SDK

See [conductor-sdk/conductor-javascript](https://github.com/conductor-sdk/conductor-javascript/blob/main/README.md)
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ nav:
- documentation/clientsdks/clojure-sdk.md
- documentation/clientsdks/go-sdk.md
- documentation/clientsdks/python-sdk.md
- documentation/clientsdks/js-sdk.md
- Resources:
- Contributing: resources/contributing.md
- Code of Conduct: resources/code-of-conduct.md
Expand Down

0 comments on commit 235b5c1

Please sign in to comment.