{
  "version": "1.8.2",
  "timeZone": "Europe/Berlin",
  "title": "A simple example of a Python UDS shell job.",
  "instructions": [
    {
      "TYPE": "Fork",
      "branches": [
        {
          "id": "branch1",
          "workflow": {
            "instructions": [
              {
                "TYPE": "Execute.Named",
                "jobName": "start_uds_server",
                "label": "start_uds_server"
              }
            ]
          }
        },
        {
          "id": "branch2",
          "workflow": {
            "instructions": [
              {
                "TYPE": "Sleep",
                "duration": "2",
                "label": "sleep_2_seconds"
              },
              {
                "TYPE": "Execute.Named",
                "jobName": "start_uds_client",
                "label": "start_uds_client"
              }
            ]
          }
        }
      ],
      "joinIfFailed": false
    }
  ],
  "jobs": {
    "start_uds_server": {
      "agentName": "testAgent",
      "withSubagentClusterIdExpr": false,
      "executable": {
        "TYPE": "ShellScriptExecutable",
        "script": "#!/usr/bin/python3\n \nimport socket\nimport os\nimport json\n \n# Defines the socket file path\nsocket_path = \"/tmp/example.sock\"\n \n# Removes the socket file if it exists from a previous session\nif os.path.exists(socket_path):\n    os.remove(socket_path)\n \n# Configures the server\nserver = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)\nserver.bind(socket_path)\nserver.listen(1) # Allows 1 pending connection\n \nprint(f\"UDS server listening on: {socket_path}\")\n \nserver_is_running = True\n \n# Starts the listener\nwhile server_is_running:\n    conn, _ = server.accept()\n    data = conn.recv(1024)\n \n    if not data:\n        conn.close()\n        continue\n \n    print(\"server received:\", data.decode(\"utf-8\"))\n     \n    # Sends the response to the client\n    response = json.dumps({\"message\": \"hello client!\"})\n    conn.sendall(response.encode(\"utf-8\"))\n     \n    # Closes the connection\n    conn.close()\n     \n    # Stops the server\n    server_is_running = False",
        "v1Compatible": false
      },
      "skipIfNoAdmissionForOrderDay": false,
      "killAtEndOfAdmissionPeriod": false,
      "parallelism": 1,
      "graceTimeout": 1,
      "failOnErrWritten": false,
      "warnOnErrWritten": false,
      "title": "A simple UDS server.",
      "isNotRestartable": false
    },
    "start_uds_client": {
      "agentName": "testAgent",
      "withSubagentClusterIdExpr": false,
      "executable": {
        "TYPE": "ShellScriptExecutable",
        "script": "#!/usr/bin/python3\n \nimport json\nimport socket\n \n# Defines the socket file path\nsocket_path = \"/tmp/example.sock\"\n \n# Starts the connection\nclient = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)\nclient.connect(socket_path)\n \n# Sends the request to the server\nrequest = json.dumps({\"message\": \"hello server!\"})\nclient.sendall(request.encode(\"utf-8\"))\n \n# Prints the server response\nresponse = client.recv(1024)\nprint(\"client received:\", response.decode(\"utf-8\"))\n \n# Closes the connection\nclient.close()",
        "v1Compatible": false
      },
      "skipIfNoAdmissionForOrderDay": false,
      "killAtEndOfAdmissionPeriod": false,
      "parallelism": 1,
      "graceTimeout": 1,
      "failOnErrWritten": false,
      "warnOnErrWritten": false,
      "title": "A simple UDS client.",
      "isNotRestartable": false
    }
  }
}