Skip to content

Commit

Permalink
Merge branch 'main' into feat/typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrielBento committed Dec 14, 2023
2 parents 0e8d0ee + 70bffd2 commit c872132
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions eigr_io/blog/2023-12-03-distributed-elixir-made-easy.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Let's delve into a quick comparison between a traditional GenServer approach and

### Consider a GenServer that does the following:

```ELIXIR
```elixir
defmodule Incrementor do
use GenServer

Expand All @@ -40,7 +40,7 @@ end

If we execute it, as you probably now already, we can add a specified value to the total stored in memory, and calling add will always return the total amount stored in memory.

```Elixir
```elixir
iex(1)> {:ok, pid} = GenServer.start_link(Incrementor, [])
iex(2)> GenServer.call(pid, {:add, 1})
{:ok, %{total: 1}}
Expand All @@ -53,7 +53,7 @@ iex(3)> GenServer.call(pid, {:add, 1})

Our process defined by the `GenServer`, we call it an _Actor_.

```ELIXIR
```elixir
defmodule IncrementorActor do
use SpawnSdk.Actor,
name: "incrementor",
Expand Down Expand Up @@ -81,7 +81,7 @@ end

Our application would look like:

```ELIXIR
```elixir
defmodule Example.Application do
@moduledoc false
use Application
Expand All @@ -106,7 +106,7 @@ end

And the SDK can be installed in your Elixir project with:

```ELIXIR
```elixir
[
{:spawn_sdk, "~> 1.1"},
# if using stateful actors
Expand All @@ -120,15 +120,15 @@ When using a statestore, you need to define a statestore key in `config.exs` or

> **NOTE:** It is **recommended** to securely store the key in the environment where it is being used.
```ELIXIR
```elixir
config :spawn_statestores, statestore_key: "secure_database_key"
```

Having that defined, the same for `Calling` or `Casting` a process in a GenServer, we do it with `invoke`.

Passing any message we want in the payload attribute, it needs to be a struct or map that can be encoded to JSON or a protobuf struct.

```Elixir
```elixir
iex(1)> SpawnSdk.invoke("incrementor", system: "spawn-system", action: "add", payload: %{value: 1})
{:ok, %{total: 1}}
```
Expand Down Expand Up @@ -178,7 +178,7 @@ You can even invoke an actor registered in a different system or in the same sys

For instance, if we wanted to invoke the same actor we wrote but in a [NodeJS ActorHost](https://github.com/eigr/spawn-node-sdk), it would look like this:

```TS
```ts
import spawn from '@eigr/spawn-sdk'

const response = await spawn.invoke('incrementor', {
Expand All @@ -201,7 +201,7 @@ However for production we **recommend** using our CRDs set up for you.

First of all you need to install our k8s CRD with the following manifest (using kubectl):

```BASH
```bash
kubectl create ns eigr-functions && curl -L https://github.com/eigr/spawn/releases/download/v1.1.1/manifest.yaml | kubectl apply -f -
```

Expand Down Expand Up @@ -259,7 +259,7 @@ spec:
```

Just by applying this configuration, and having a container that has the application with the example we wrote in the start of the article, we should see
the instances starting that should handle the clustering and all the heavy insfrastructure work for you.
the instances starting that should handle the clustering and all the heavy infrastructure work for you.

## Managing State Resilience with Spawn

Expand Down
8 changes: 4 additions & 4 deletions eigr_io/docs/projects-spawn/spawn-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -549,14 +549,14 @@ spec:
This file will be responsible for deploying your host function and actors in the cluster.
Now that the files have been defined, we can apply them to the cluster:
```shell
```bash
kubectl apply -f system.yaml
kubectl apply -f node.yaml
```

After that, just check your actors with:

```shell
```bash
kubectl get actornodes
```

Expand All @@ -566,13 +566,13 @@ kubectl get actornodes
Tests:

```shell
```bash
make test
```

Run:

```shell
```bash
make build run-proxy-local
```

Expand Down

0 comments on commit c872132

Please sign in to comment.