Skip to content

Instantly share code, notes, and snippets.

View dasch's full-sized avatar
💭
LOOKING INTENTLY INTO THE VOID

Daniel Schierbeck dasch

💭
LOOKING INTENTLY INTO THE VOID
View GitHub Profile
# app/controllers/posts_controller.rb
class PostsController < ApplicationController
def show
@post = Post.find(params[:id])
event = {
post_id: @post.id,
ip_address: request.remote_ip,
timestamp: Time.now,
}
@dasch
dasch / README.md
Last active July 7, 2017 12:38
Event Sourcing Example

The rules of the reservation of a train are the following:

  • We cannot reserve seats in a train if it bumps up the occupancy over 70%
  • All the reserved seats should be in the same coach (we cannot separate families)
  • Preferably, we should avoid bumping the occupancy of a coach over 80%
# app/consumers/hello_consumer.rb
class HelloConsumer < Racecar::Consumer
subscribes_to "some-topic"
def process(message)
puts "Received message: #{message.value}"
end
end
class Consumer
class Fetcher
def initialize(input, output)
@input, @output = input, output
@running = true
end
def run
while @running
class IoFuture
def initialize(io, &block)
@io, @block = io, block
end
def to_io
@io
end
def value
module SearchQueryIndexer exposing (main)
import Stream exposing (Stream, Pipeline)
main : Pipeline
main =
Stream.readFrom "searches"
|> Stream.filter (\search -> search.resultCount > 0)
module Kafka.Consumer where
import Kafka
type alias Config =
{ groupId : String
, checkpointInterval : Maybe Int
, checkpointThreshold : Maybe Int
, heartbeatInterval : Int
}
module Aggregate exposing (..)
type alias Aggregate cmd error event state =
{ init : state
, apply : event -> state -> state
, handle : cmd -> state -> Result error event
}
type alias Coder cmd event =
{ decodeEvent : String -> Result String event
impressions : Stream (ImpressionId, Impression)
clicks : Stream (ImpressionId, Click)
-- One element per key with lists of input elements.
matches : Stream (ImpressionId, (List Impression, List Click))
matches =
Stream.join impressions clicks
-- One element per input-pair match.
matches : Stream (ImpressionId, (Impression, Click))
module Foosball.Game exposing (..)
type Team = BlueTeam | RedTeam
type alias Player = String
type alias Score = Int
type Event
= PlayerAdded { team : Team, player : Player }
| PlayerRemoved { player : Player }
| ScoreAdded { team : Team, score : Score }