Skip to content

Commit

Permalink
Allow looping during workflows, and detect disconnected segments (#107)
Browse files Browse the repository at this point in the history
* Allow looping during workflows, and detect disconnected segments
  • Loading branch information
liamg authored Nov 13, 2023
1 parent 53d22b1 commit 04ecebe
Show file tree
Hide file tree
Showing 18 changed files with 254 additions and 211 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ jobs:
uses: actions/checkout@v4
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
uses: docker/build-push-action@v5
with:
context: .
push: true
Expand Down
10 changes: 8 additions & 2 deletions backend/server/api/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import (
)

func (a *API) RunWorkflow(w *workflow.WorkflowM) {
go a.runWorkflow(w)
}

func (a *API) runWorkflow(w *workflow.WorkflowM) {
a.workflowMu.Lock()
defer a.workflowMu.Unlock()
if a.runningWorkflowID != uuid.Nil {
Expand All @@ -38,7 +42,6 @@ func (a *API) RunWorkflow(w *workflow.WorkflowM) {
go func() {
for update := range updateChan {
_ = a.eventTrigger(EventWorkflowUpdate, update.Pack())

if n, err := flow.FindNode(update.Node); err == nil {
_ = a.eventTrigger(EventWorkflowOutput, node.OutputM{
Node: update.Node.String(),
Expand Down Expand Up @@ -66,9 +69,12 @@ func (a *API) RunWorkflow(w *workflow.WorkflowM) {
}
}

func (a *API) StopWorkflow(w *workflow.WorkflowM) {
func (a *API) StopWorkflow() {
if a.workflowContextCancel != nil {
a.logger.Info("Stopping workflow!")
a.workflowContextCancel()
} else {
a.logger.Info("No workflow to stop!")
}
}

Expand Down
36 changes: 18 additions & 18 deletions backend/server/bindings/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func generateClient(summary Summary) error {
markerMethodsStart,
{'\n'},
methods,
{' ', ' '},
markerMethodsEnd,
afterMethods,
}, []byte{})
Expand All @@ -64,14 +65,14 @@ func generateClientMethods(summary Summary) ([]byte, []byte, error) {
}
if len(method.OutTypes) == 0 {

_, _ = fmt.Fprintf(buffer, ` %s(%s): Promise<void> {
return new Promise<void>((resolve, reject) => {
const receive = () => {
resolve();
}
this.callMethod("%[1]s", [%[3]s], receive, reject);
})
}
_, _ = fmt.Fprintf(buffer, ` %s(%s): Promise<void> {
return new Promise<void>((resolve, reject) => {
const receive = () => {
resolve()
}
this.callMethod('%[1]s', [%[3]s], receive, reject)
})
}
`,
method.Name,
Expand All @@ -88,20 +89,19 @@ func generateClientMethods(summary Summary) ([]byte, []byte, error) {
panic(fmt.Sprintf("method %s has empty output type", method.Name))
}
promiseTypes = append(promiseTypes, outType.TSProp())
outputs += fmt.Sprintf("\n let output%d: %s = JSON.parse(args[%d])", i, outType.TSProp(), i)
outputs += fmt.Sprintf("\n const output%d: %s = JSON.parse(args[%d])", i, outType.TSProp(), i)
outputList = append(outputList, fmt.Sprintf("output%d", i))
}
promiseType := strings.Join(promiseTypes, ", ")

_, _ = fmt.Fprintf(buffer, ` %s(%s): Promise<%s> {
return new Promise<%[3]s>((resolve, reject) => {
const receive = (args: string[]) => {
%s
resolve(%s);
}
this.callMethod("%[1]s", [%[6]s], receive, reject);
})
}
_, _ = fmt.Fprintf(buffer, ` %s(%s): Promise<%s> {
return new Promise<%[3]s>((resolve, reject) => {
const receive = (args: string[]) => {%s
resolve(%s)
}
this.callMethod('%[1]s', [%[6]s], receive, reject)
})
}
`,
method.Name,
Expand Down
8 changes: 6 additions & 2 deletions backend/server/bindings/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@ func generateTypes(summary Summary) error {
_, _ = fmt.Fprint(file, "\n")
}

for _, t := range types {
_, _ = fmt.Fprint(file, t.TSDefinition()+"\n\n")
for i, t := range types {
if i > 0 {
_, _ = fmt.Fprint(file, "\n\n")
}
_, _ = fmt.Fprint(file, t.TSDefinition())
}
_, _ = fmt.Fprint(file, "\n")

if err := os.WriteFile(filepath.Join(basePath, dir, "index.ts"), file.Bytes(), 0644); err != nil {
return fmt.Errorf("failed to write file '%s': %w", filepath.Join(dir, "index.ts"), err)
Expand Down
Loading

0 comments on commit 04ecebe

Please sign in to comment.