{"action":"created","issue":{"url":"https://api.github.com/repos/arkency/ruby_event_store/issues/17","repository_url":"https://api.github.com/repos/arkency/ruby_event_store","labels_url":"https://api.github.com/repos/arkency/ruby_event_store/issues/17/labels{/name}","comments_url":"https://api.github.com/repos/arkency/ruby_event_store/issues/17/comments","events_url":"https://api.github.com/repos/arkency/ruby_event_store/issues/17/events","html_url":"https://github.com/arkency/ruby_event_store/pull/17","id":155678592,"number":17,"title":"Adds write lock strategy per aggregates","user":{"login":"gottfrois","id":943784,"avatar_url":"https://avatars.githubusercontent.com/u/943784?v=3","gravatar_id":"","url":"https://api.github.com/users/gottfrois","html_url":"https://github.com/gottfrois","followers_url":"https://api.github.com/users/gottfrois/followers","following_url":"https://api.github.com/users/gottfrois/following{/other_user}","gists_url":"https://api.github.com/users/gottfrois/gists{/gist_id}","starred_url":"https://api.github.com/users/gottfrois/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gottfrois/subscriptions","organizations_url":"https://api.github.com/users/gottfrois/orgs","repos_url":"https://api.github.com/users/gottfrois/repos","events_url":"https://api.github.com/users/gottfrois/events{/privacy}","received_events_url":"https://api.github.com/users/gottfrois/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-05-19T08:18:12Z","updated_at":"2016-06-07T07:59:23Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/arkency/ruby_event_store/pulls/17","html_url":"https://github.com/arkency/ruby_event_store/pull/17","diff_url":"https://github.com/arkency/ruby_event_store/pull/17.diff","patch_url":"https://github.com/arkency/ruby_event_store/pull/17.patch"},"body":"#### Overview\r\n\r\nThis changes allow to perform a database lock per aggregates in order to avoid concurrency issues in a concurrent environment, such as, multi-threaded env or load balanced event store (multiple event store processes trying to create events on the database at the same time).\r\n\r\nThe lock only blocks the aggregate, not the entire event table. A `RubyEventStore::CannotObtainLock` exception is raised in case the lock could not be obtained. Meaning an event store was already trying to perform an `INSERT` on the given aggregate.\r\n\r\nClient's implementation should catch this exception and perform a simple `retry` in a `begin`/`rescue` block:\r\n\r\n```ruby\r\naggregate_id = SecureRandom.uuid\r\nclient = RailsEventStore::Client.new(lock_obtainer: RailsEventStoreActiveRecord::LockObtainer.new)\r\n\r\nbegin\r\n  event = OrderCreated.new(data: \"sample\", event_id: SecureRandom.uuid)\r\n  client.publish_event(event, aggregate_id)\r\nrescue RubyEventStore::CannotObtainLock\r\n  retry\r\nend\r\n```"},"comment":{"url":"https://api.github.com/repos/arkency/ruby_event_store/issues/comments/224207817","html_url":"https://github.com/arkency/ruby_event_store/pull/17#issuecomment-224207817","issue_url":"https://api.github.com/repos/arkency/ruby_event_store/issues/17","id":224207817,"user":{"login":"mpraglowski","id":171015,"avatar_url":"https://avatars.githubusercontent.com/u/171015?v=3","gravatar_id":"","url":"https://api.github.com/users/mpraglowski","html_url":"https://github.com/mpraglowski","followers_url":"https://api.github.com/users/mpraglowski/followers","following_url":"https://api.github.com/users/mpraglowski/following{/other_user}","gists_url":"https://api.github.com/users/mpraglowski/gists{/gist_id}","starred_url":"https://api.github.com/users/mpraglowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpraglowski/subscriptions","organizations_url":"https://api.github.com/users/mpraglowski/orgs","repos_url":"https://api.github.com/users/mpraglowski/repos","events_url":"https://api.github.com/users/mpraglowski/events{/privacy}","received_events_url":"https://api.github.com/users/mpraglowski/received_events","type":"User","site_admin":false},"created_at":"2016-06-07T07:59:23Z","updated_at":"2016-06-07T07:59:23Z","body":"`make mutate` is your friend ;) ping me if you need any help :)"}}
{"actor":{"display_login":"mpraglowski"}}