Hot Reload#

While developing your Orchestration, you may want it to reload automatically as you change the YAML configuration.

For this you can use the Orchestration’s reload argument to reload it with the updated configuration every time you change the YAML configuration.

Caution

This feature aims to let developers iterate faster while developing, but is not intended for production use.

Note

This feature requires watchfiles>=0.18 to be installed.

To see how this works, let’s define a Deployment in deployment.yml with a reload option:

jtype: Deployment
uses: ConcatenateTextExecutor
uses_with:
  text_to_concat: foo
with:
  port: 12345
  reload: True

Load and expose the Orchestration:

import os
from jina import Deployment, Executor, requests
from docarray import DocList
from docarray.documents import TextDoc


class ConcatenateTextExecutor(Executor):
    @requests
    def foo(self, docs: DocList[TextDoc], **kwargs) -> DocList[TextDoc]:
        for doc in docs:
            doc.text += text_to_concat
        return docs


os.environ['JINA_LOG_LEVEL'] = 'DEBUG'


dep = Deployment.load_config('deployment.yml')

with dep:
    dep.block()

You can see that the Orchestration is running and serving:

from jina import Client
from docarray import DocList
from docarray.documents import TextDoc

c = Client(port=12345)

print(c.post(on='/', inputs=DocList[TextDoc](TextDoc()), return_type=DocList[TextDoc])[0].text)
foo

You can edit the Orchestration YAML file and save the changes:

jtype: Deployment
uses: ConcatenateTextExecutor
uses_with:
  text_to_concat: bar
with:
  port: 12345
  reload: True

You should see the following in the Orchestration’s logs:

INFO   Deployment@28301 change in Deployment YAML deployment.yml observed, restarting Deployment                                                   

After this, the behavior of the Deployment’s Executor will change:

from jina import Client
from docarray import DocList
from docarray.documents import TextDoc

c = Client(port=12345)

print(c.post(on='/', inputs=DocList[TextDoc](TextDoc()), return_type=DocList[TextDoc])[0].text)
bar

To see how this works, let’s define a Flow in flow.yml with a reload option:

jtype: Flow
with:
  port: 12345
  reload: True
executors:
- name: exec1
  uses: ConcatenateTextExecutor

Load and expose the Orchestration:

import os
from jina import Deployment, Executor, requests
from docarray import DocList
from docarray.documents import TextDoc


class ConcatenateTextExecutor(Executor):
    @requests
    def foo(self, docs: DocList[TextDoc], **kwargs) -> DocList[TextDoc]:
        for doc in docs:
            doc.text += text_to_concat
        return docs


os.environ['JINA_LOG_LEVEL'] = 'DEBUG'


f = Flow.load_config('flow.yml')

with f:
    f.block()

You can see that the Flow is running and serving:

from jina import Client
from docarray import DocList
from docarray.documents import TextDoc

c = Client(port=12345)

print(c.post(on='/', inputs=DocList[TextDoc](TextDoc()), return_type=DocList[TextDoc])[0].text)
add text

You can edit the Flow YAML file and save the changes:

jtype: Flow
with:
  port: 12345
  reload: True
executors:
- name: exec1
  uses: ConcatenateTextExecutor
- name: exec2
  uses: ConcatenateTextExecutor

You should see the following in the Flow’s logs:

INFO   Flow@28301 change in Flow YAML flow.yml observed, restarting Flow                                                   

After this, the Flow will have two Executors with the new topology:

from jina import Client
from docarray import DocList
from docarray.documents import TextDoc

c = Client(port=12345)

print(c.post(on='/', inputs=DocList[TextDoc](TextDoc()), return_type=DocList[TextDoc])[0].text)
add text add text