hyperoceanic

hyperoceanic

ECSx Component.search confusion/bug?

Had a great day or so coding against the EXSx framework - love the
Systems model to divide up the work. I’m having a bit of a moment with Component.search returning Components that I’m certain I’ve already removed. I’ve extracted the code into its own method, below.

  def get_live_assignments(worker_id) do
    dbg AssignmentWorker.search(worker_id)
    |> Enum.filter(&AssignmentWorker.exists?(&1) )
  end

I would expect search to not return records that would fail the exists? test, but that’s not what I’m seeing.

First - before removing any assignments:

[lib/taiichi/systems/worker_assignment_balancer.ex:14: Taiichi.Systems.WorkerAssignmentBalancer.get_live_assignments/1]
AssignmentWorker.search(worker_id) #=> ["9205100f-1308-4671-b8ea-a1601fc9275c", "a1399542-8bd1-4470-8892-4d4981a9a6b4"]
|> Enum.filter(&AssignmentWorker.exists?(&1)) #=> ["9205100f-1308-4671-b8ea-a1601fc9275c", "a1399542-8bd1-4470-8892-4d4981a9a6b4"]

All is good - the exists? filter returns both records returned by search. However, when I remove one of the assignments (in another System), there’s a mismatch:

[lib/taiichi/systems/worker_assignment_balancer.ex:14: Taiichi.Systems.WorkerAssignmentBalancer.get_live_assignments/1]
AssignmentWorker.search(worker_id) #=> ["9205100f-1308-4671-b8ea-a1601fc9275c", "a1399542-8bd1-4470-8892-4d4981a9a6b4"]
|> Enum.filter(&AssignmentWorker.exists?(&1)) #=> ["a1399542-8bd1-4470-8892-4d4981a9a6b4"]

Search is returning two records, while only one exists.

Here’s the definition for the Component, for reference:

defmodule Taiichi.Components.AssignmentWorker do
  @moduledoc """
  Tracks the worker who is on the assignment.
  key = assignment_id, value = worker_id.
  """
  use ECSx.Component,
    value: :binary,
    index: true
end

Besides that, I love the clarity and productivity that elixir and ECSx are bringing. I’ve built something where I can assign many people to a task, have them contribute to getting the work on the task done according to their own productivity, balance their assignments across many tasks and unassign them from completed tasks in just a few lines of code.

Any thoughts? I can always pipe calls to search into exists? but I’m worried I’m missing something obvious.

Most Liked

APB9785

APB9785

Creator of ECSx

@hyperoceanic I just released v0.5.2 with the fix for this issue. Thanks for reporting it!

APB9785

APB9785

Creator of ECSx

Hi again Mark, thanks for the kind words. Very happy to hear about your experience with Elixir + ECSx.

The issue you’re seeing appears to be a bug with ECSx.Component :index feature. Should be a simple fix, but just to confirm, could you try the same steps again but with index: false on that component?

hyperoceanic

hyperoceanic

Hi Andy - yes that solved it!

[lib/taiichi/systems/worker_assignment_balancer.ex:14: Taiichi.Systems.WorkerAssignmentBalancer.get_live_assignments/1]
AssignmentWorker.search(worker_id) #=> []
|> Enum.filter(&AssignmentWorker.exists?(&1)) #=> []

Where Next?

Popular in Questions Top

New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement