Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No matching function Bank.Account.apply_event/2 #1

Open
homanchou opened this issue Jun 11, 2016 · 3 comments
Open

No matching function Bank.Account.apply_event/2 #1

homanchou opened this issue Jun 11, 2016 · 3 comments

Comments

@homanchou
Copy link

I'm not sure what causes this error. Sometimes I get it, sometimes I don't. It seems to happen after the terminal has been open for a while... as if it's related to time.

Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (1.2.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>
nil
iex(2)>
nil
iex(3)>
nil
iex(4)>
nil
iex(5)>
nil
iex(6)> Bank.__info__(:functions)
[check_balance: 1, close: 0, create: 1, deposit: 2, open: 0, withdraw: 2]
iex(7)> Bank.open
{:ok, #PID<0.93.0>}
iex(8)> Bank.create "w"
Command Sent
Command Handler: Create Account
:ok
Event Store Published Event
Event Published
Event Handler: Account Created
Account Created
iex(9)> Bank.deposit "w" 100
** (SyntaxError) iex:9: syntax error before: 100

iex(9)> Bank.deposit "w", 100
Command Sent
Command Handler: Deposit Money
:ok
Event Store Published Event
Event Published
Event Handler: Money Deposited
Money Deposited
iex(10)> Bank.withdraw "w", 200
Command Sent
Command Handler: Withdraw Money
:ok
-100
Event Store Published Event
Event Published
Event Handler: Payment Declined
iex(11)>
13:14:57.956 [info]  Payment declined for Account: "w". Shame, shame!

iex(11)> Bank.deposit "w", 50
Command Sent
Command Handler: Deposit Money
:ok
Event Store Published Event
Event Published
Event Handler: Money Deposited
Money Deposited
iex(12)> Bank.deposit "w", -50
Command Sent
Command Handler: Deposit Money
:ok
Event Store Published Event
Event Published
Event Handler: Money Deposited
Money Deposited
iex(13)> Bank.check_balance
** (UndefinedFunctionError) undefined function Bank.check_balance/0
    (elixir_cqrs_es) Bank.check_balance()
iex(13)> Bank.deposit "w", 50
Command Sent
Command Handler: Deposit Money
:ok
Event Store Published Event
Event Published
Event Handler: Money Deposited
Money Deposited
iex(14)> Bank.check_balance "w"
150
iex(15)> Bank.deposit "w", 50
Command Sent
Command Handler: Deposit Money
:ok
Event Store Published Event
Event Published
Event Handler: Money Deposited
Money Deposited
iex(16)> Bank.check_balance "w"
200
iex(17)> Bank.deposit "w" 100
** (SyntaxError) iex:17: syntax error before: 100

iex(17)> Bank.deposit "w", 100
Command Sent
Command Handler: Deposit Money
:ok
iex(18)>
13:16:52.647 [error] Process #PID<0.119.0> raised an exception
** (FunctionClauseError) no function clause matching in Bank.Account.apply_event/2
    (elixir_cqrs_es) lib/bank/account.ex:116: Bank.Account.apply_event({:transaction_date, {{2016, 6, 11}, {13, 15, 36}}}, %Bank.Account.State{balance: 0, changes: [], date_created: nil, id: nil})
    (elixir_cqrs_es) lib/bank/account.ex:140: Bank.Account.apply_many_events/2
    (elixir_cqrs_es) lib/bank/account.ex:70: Bank.Account.loop/1
@homanchou
Copy link
Author

Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (1.2.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> :os.system_time(:milli_seconds)
1465676397801
iex(2)> Bank.open
{:ok, #PID<0.88.0>}
iex(3)> Bnak.create "w"
** (UndefinedFunctionError) undefined function Bnak.create/1 (module Bnak is not available)
    Bnak.create("w")
iex(3)> Bank.create "w"
Command Sent
Command Handler: Create Account
:ok
Event Store Published Event
Event Published
Event Handler: Account Created
Account Created
iex(4)> :os.system_time(:milli_seconds)
1465676423151
iex(5)> Bank.deposit "w", 5
Command Sent
Command Handler: Deposit Money
:ok
iex(6)>
13:24:13.825 [error] Process #PID<0.99.0> raised an exception
** (FunctionClauseError) no function clause matching in Bank.Account.apply_event/2
    (elixir_cqrs_es) lib/bank/account.ex:116: Bank.Account.apply_event({:id, "w"}, %Bank.Account.State{balance: 0, changes: [], date_created: nil, id: nil})
    (elixir_cqrs_es) lib/bank/account.ex:140: Bank.Account.apply_many_events/2
    (elixir_cqrs_es) lib/bank/account.ex:70: Bank.Account.loop/1

nil
iex(7)> :os.system_time(:milli_seconds)
1465676657263
iex(8)>

@jfis
Copy link

jfis commented Aug 20, 2016

in case anyone runs into this...

in Event Store

def append_events(key, events) do
  stored_events = get_raw_events(key)
  new_events = :lists.reverse(events)
  combined_events = new_events ++ stored_events

  :ets.insert(@table_id, {key, combined_events})

  for e <- new_events do
    IO.puts "Event Store Published Event"
    EventBus.publish_event(e)
  end
end

@homanchou
Copy link
Author

I think the culprit is that when a bank account is opened it spawns a new process that executes a loop in account.ex. But this loop has a timeout after 10 seconds and it isn't monitored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants