mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-11-10 14:11:29 +08:00
Improvements to notebooks that rely on distribution
This commit is contained in:
parent
652efd6bad
commit
0b6f416bbc
2 changed files with 22 additions and 19 deletions
|
|
@ -13,6 +13,8 @@ For a more structured introduction to the language, see [Elixir's
|
||||||
Getting Started guide](https://elixir-lang.org/getting-started/introduction.html)
|
Getting Started guide](https://elixir-lang.org/getting-started/introduction.html)
|
||||||
and [the many learning resources available](https://elixir-lang.org/learning.html).
|
and [the many learning resources available](https://elixir-lang.org/learning.html).
|
||||||
|
|
||||||
|
<!-- livebook:{"break_markdown":true} -->
|
||||||
|
|
||||||
### The plan ahead
|
### The plan ahead
|
||||||
|
|
||||||
The Portal game consists of a series of puzzles that must be
|
The Portal game consists of a series of puzzles that must be
|
||||||
|
|
@ -647,6 +649,8 @@ However, before we start, there is one big disclaimer:
|
||||||
> resources available for Elixir, which will provide a more solid ground to
|
> resources available for Elixir, which will provide a more solid ground to
|
||||||
> leverage the Erlang VM and its distributed features.
|
> leverage the Erlang VM and its distributed features.
|
||||||
|
|
||||||
|
<!-- livebook:{"break_markdown":true} -->
|
||||||
|
|
||||||
### Distribution 101
|
### Distribution 101
|
||||||
|
|
||||||
When Livebook executes the code in a notebook, it starts a separate Elixir
|
When Livebook executes the code in a notebook, it starts a separate Elixir
|
||||||
|
|
@ -694,6 +698,8 @@ Node.get_cookie()
|
||||||
|
|
||||||
Now we have everything we need to connect across notebooks.
|
Now we have everything we need to connect across notebooks.
|
||||||
|
|
||||||
|
<!-- livebook:{"break_markdown":true} -->
|
||||||
|
|
||||||
### Notebook connections
|
### Notebook connections
|
||||||
|
|
||||||
In order to connect across notebooks, open up [a new empty notebook](/explore/notebooks/new)
|
In order to connect across notebooks, open up [a new empty notebook](/explore/notebooks/new)
|
||||||
|
|
@ -757,9 +763,9 @@ Portal code has been defined in this notebook but it is not available
|
||||||
in the other notebook. If we were working on an actual Elixir project,
|
in the other notebook. If we were working on an actual Elixir project,
|
||||||
this issue wouldn't exist, because we would start multiple nodes on top
|
this issue wouldn't exist, because we would start multiple nodes on top
|
||||||
of the same codebase with the same modules, but we can't do so here.
|
of the same codebase with the same modules, but we can't do so here.
|
||||||
To work around this, you should simply copy the cell that define the
|
To work around this, copy the cell that defines the `Portal.Door` module
|
||||||
`Portal.Door` module from this notebook into the other notebook and
|
from this notebook into the other notebook and execute it. Now in the other
|
||||||
execute it. Now we should be able to shoot a door in the other node:
|
node you should be able to start a door:
|
||||||
|
|
||||||
<!-- livebook:{"force_markdown":true} -->
|
<!-- livebook:{"force_markdown":true} -->
|
||||||
|
|
||||||
|
|
@ -767,12 +773,14 @@ execute it. Now we should be able to shoot a door in the other node:
|
||||||
Portal.Door.start_link(:blue)
|
Portal.Door.start_link(:blue)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
<!-- livebook:{"break_markdown":true} -->
|
||||||
|
|
||||||
### Cross-node references
|
### Cross-node references
|
||||||
|
|
||||||
Now that we have spawned a door on the other notebook, we can directly read
|
Now that we have spawned a door on the other notebook, we can directly read
|
||||||
its content from this notebook. So far, we have been using an atom, such
|
its content from this notebook. So far, we have been using atoms to represent
|
||||||
as `:blue`, to represent the doors, but we can also use the `{name, node}`
|
doors, such as `:blue`, but we can also use the `{name, node}` notation to refer
|
||||||
notation to refer to a process in another node. Let's give it a try:
|
to a process in another node. Let's give it a try:
|
||||||
|
|
||||||
```elixir
|
```elixir
|
||||||
blue = {:blue, other_node}
|
blue = {:blue, other_node}
|
||||||
|
|
|
||||||
|
|
@ -24,25 +24,20 @@ alias VegaLite, as: Vl
|
||||||
|
|
||||||
## Connecting to a remote node
|
## Connecting to a remote node
|
||||||
|
|
||||||
While Livebook can run a notebook directly inside a remote node,
|
The first thing we need is a separate Elixir node. In practice,
|
||||||
this time we will connect to a running node manually to minimize
|
you would start an external Elixir system, such as by running the
|
||||||
the impact in the remote system. This will also give you a better
|
following in your production app:
|
||||||
idea of how you can inspect a remote node in general.
|
|
||||||
|
|
||||||
The first thing we need is a separate Elixir node. For this example,
|
|
||||||
you can do so by opening up [a new notebook](/explore/notebooks/new),
|
|
||||||
since Livebook automatically starts each notebook as a remote node.
|
|
||||||
|
|
||||||
In practice, you may want to start an existing Elixir system,
|
|
||||||
such as by running the following in your production app:
|
|
||||||
|
|
||||||
```
|
```
|
||||||
elixir --name my_app@IP -S mix TASK
|
iex --name my_app@IP -S mix TASK
|
||||||
```
|
```
|
||||||
|
|
||||||
Or by connecting to a production assembled via
|
Or by connecting to a production node assembled via
|
||||||
[`mix release`](https://hexdocs.pm/mix/Mix.Tasks.Release.html).
|
[`mix release`](https://hexdocs.pm/mix/Mix.Tasks.Release.html).
|
||||||
|
|
||||||
|
For convenience, however, you can simply start [a new notebook](/explore/notebooks/new),
|
||||||
|
since Livebook automatically starts each notebook as a remote node.
|
||||||
|
|
||||||
Once you start a new notebook, you can find its node name and
|
Once you start a new notebook, you can find its node name and
|
||||||
cookie by running the following inside an Elixir cell:
|
cookie by running the following inside an Elixir cell:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue