Skip to content

Commit

Permalink
rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongnb14 committed Aug 30, 2024
1 parent bce6943 commit 779c12d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
8 changes: 4 additions & 4 deletions examples/outputs/sequence_diagram.mmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ sequenceDiagram
activate Github Runner
Azure--)-Github Runner:Token
Github Runner->>+MCR:Push docker image
MCR--)-Github Runner:ok
MCR--)+Github Runner:ok
Github Runner->>+AKS:Check existing install
AKS--)-Github Runner:ok
AKS--)+Github Runner:ok
Note right of AKS: Conditionally<br/>Force Uninstall
Note over Github Runner, AKS: optional
Github Runner->>+AKS:Helm Install dry run
AKS--)-Github Runner:ok
AKS--)+Github Runner:ok
rect rgb(224, 255, 255)
Github Runner->>+AKS:Helm Install
Github Runner->>AKS:Check deployment status
AKS->>+MCR:Pull docker image
MCR--)-AKS:ok
MCR--)+AKS:ok
AKS->>AKS:Deploy app
loop Wait
AKS->>AKS:Check IP Address
Expand Down
18 changes: 9 additions & 9 deletions examples/test_sequence_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@ def test_sequence_diagram():
mcr = sd.Participant(sequence_diagram=diagram, name="MCR")
aks = sd.Participant(sequence_diagram=diagram, name="AKS")

runner.sync_message(azure, message="Login", state=sd.State.ACTIVATE)
runner.send(azure, message="Login", active=True)
runner.activate()

azure.return_message(runner, message="Token", state=sd.State.DEACTIVATE)
azure.return_message(runner, message="Token", active=False)

runner.call_and_wait_response(mcr, message="Push docker image")
runner.call_and_wait_response(aks, message="Check existing install")
runner.send_and_wait_response(mcr, message="Push docker image")
runner.send_and_wait_response(aks, message="Check existing install")
aks.note("Conditionally<br/>Force Uninstall")
diagram.note_over("optional", runner, aks)

runner.call_and_wait_response(aks, message="Helm Install dry run")
runner.send_and_wait_response(aks, message="Helm Install dry run")

with diagram.fragment(sd.Fragment.BACKGROUND, Color.hex_to_rgb(Color.CYAN)) as _:
runner.sync_message(aks, message="Helm Install", state=sd.State.ACTIVATE)
runner.sync_message(aks, message="Check deployment status")
runner.send(aks, message="Helm Install", active=True)
runner.send(aks, message="Check deployment status")

aks.call_and_wait_response(mcr, message="Pull docker image")
aks.send_and_wait_response(mcr, message="Pull docker image")
aks.self_message(message="Deploy app")

with diagram.fragment(sd.Fragment.LOOP, "Wait") as _:
aks.self_message(message="Check IP Address")

aks.return_message(runner, message="IP Address", state=sd.State.DEACTIVATE)
aks.return_message(runner, message="IP Address", active=False)
runner.deactivate()

diagram.save(current_dir + "/outputs/sequence_diagram.mmd")
Expand Down
22 changes: 17 additions & 5 deletions mermaid_builder/sequence_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,25 @@ def __init__(self, sequence_diagram, name, is_actor=False):
def set_sequence_diagram(self, sequence_diagram):
self.sequence_diagram = sequence_diagram

def sync_message(self, to, message, state=''):
def _get_state_char(self, active):
state = ""
if active is not None:
if active:
state = State.ACTIVATE
else:
state = State.DEACTIVATE
return state

def send(self, to, message, active=None):
state = self._get_state_char(active)
self.sequence_diagram.add_record(f"{self.name}{Arrow.SYNC}{state}{to.name}:{message}")

def async_message(self, to, message, state=''):
def asend(self, to, message, active=None):
state = self._get_state_char(active)
self.sequence_diagram.add_record(f"{self.name}{Arrow.ASYNC}{state}{to.name}:{message}")

def return_message(self, to, message, state=''):
def return_message(self, to, message, active=None):
state = self._get_state_char(active)
self.sequence_diagram.add_record(f"{self.name}{Arrow.RETURN}{state}{to.name}:{message}")

def self_message(self, message):
Expand All @@ -108,6 +120,6 @@ def activate(self):
def deactivate(self):
self.sequence_diagram.add_record(f"deactivate {self.name}")

def call_and_wait_response(self, to, message, response_message="ok"):
self.sync_message(to, message, State.ACTIVATE)
def send_and_wait_response(self, to, message, response_message="ok"):
self.send(to, message, State.ACTIVATE)
to.return_message(self, response_message, State.DEACTIVATE)

0 comments on commit 779c12d

Please sign in to comment.