hirethunk/verbs

[Bug]: Firing more than 1 event will fail with Thunk\Verbs\Exceptions\ConcurrencyException

Closed this issue · 1 comments

What happened?

I run php artisan plus two times, and the second time an exception is thrown:

~/dev/php/verbs-example on  main ⌚ 23:01:12
$ pa plus

~/dev/php/verbs-example on  main ⌚ 23:01:44
$ pa plus

   Thunk\Verbs\Exceptions\ConcurrencyException

  An event with ID 171002213584609280 has been written to the database for 'App\States\ApplicationState' with ID 171002213622358016. This is higher than the in-memory value of .

  at vendor/hirethunk/verbs/src/Lifecycle/EventStore.php:118
    114▕             $max_written_id = (int) data_get($result, 'max_event_id');
    115▕             $max_expected_id = $max_event_ids->get($state_type.$state_id, 0);
    116▕
    117▕             if ($max_written_id > $max_expected_id) {
  ➜ 118▕                 throw new ConcurrencyException("An event with ID {$max_written_id} has been written to the database for '{$state_type}' with ID {$state_id}. This is higher than the in-memory value of {$max_expected_id}.");
    119▕             }
    120▕         });
    121▕     }
    122▕

      +17 vendor frames

  18  artisan:13
      Illuminate\Foundation\Application::handleCommand(Object(Symfony\Component\Console\Input\ArgvInput))

How to reproduce the bug

Checkout https://github.com/remyhonig/verbs-example, run migrations and run plus command two times

  • php artisan plus
  • php artisan plus

Package Version

0.4.3

PHP Version

8.3.4

Laravel Version

11.4.0

Which operating systems does with happen with?

macOS

Notes

No response

my fault, I changed the state in the handle function, instead of the apply function