wrangling the internet of things with haskell production haskell - - PowerPoint PPT Presentation

wrangling the internet of things with haskell production
SMART_READER_LITE
LIVE PREVIEW

wrangling the internet of things with haskell production haskell - - PowerPoint PPT Presentation

wrangling the internet of things with haskell production haskell Reid Draper @reiddraper production haskell Reid Draper @reiddraper production haskell today production haskell at helium 12 months in lowest defect rate lowest defect rate


slide-1
SLIDE 1

production haskell

Reid Draper @reiddraper

wrangling the internet of things with haskell

slide-2
SLIDE 2

production haskell

Reid Draper @reiddraper

slide-3
SLIDE 3

production haskell today

slide-4
SLIDE 4

production haskell at helium

12 months in

slide-5
SLIDE 5

lowest defect rate

slide-6
SLIDE 6

easiest to refactor lowest defect rate

slide-7
SLIDE 7

OSS libraries for everything* most enjoyable easiest to refactor lowest defect rate

slide-8
SLIDE 8

20k LOC

slide-9
SLIDE 9

5 developers 20k LOC

slide-10
SLIDE 10

6 production services 5 developers 20k LOC

slide-11
SLIDE 11

build deploy monitor test develop

slide-12
SLIDE 12

build deploy monitor test develop

slide-13
SLIDE 13

cabal hell

slide-14
SLIDE 14

cabal hell

slide-15
SLIDE 15

stack

haskellstack.org

slide-16
SLIDE 16
slide-17
SLIDE 17

project specific snapshot ghc packages

slide-18
SLIDE 18
slide-19
SLIDE 19

2 seconds 20k LOC

slide-20
SLIDE 20
slide-21
SLIDE 21
  • rdeal

github.com/reiddraper/ordeal

slide-22
SLIDE 22

stack build self-contained executable

slide-23
SLIDE 23

build deploy monitor test develop

slide-24
SLIDE 24

app assets images favicon.ico javascript site.js stylesheet site.css bin app

slide-25
SLIDE 25

restart app ln -s app-370b347 current tar -xzf app-370b347.tgz

slide-26
SLIDE 26

restart app ln -s app-83181ad current

slide-27
SLIDE 27

60MB

slide-28
SLIDE 28
slide-29
SLIDE 29

build deploy monitor test develop

slide-30
SLIDE 30

ekg

slide-31
SLIDE 31
slide-32
SLIDE 32

stdout file syslog

slide-33
SLIDE 33

build deploy monitor test develop

slide-34
SLIDE 34

QuickCheck

slide-35
SLIDE 35

propEvent :: Event -> Bool propEvent a = Just a == decode (encode a)

slide-36
SLIDE 36

Event roundtrips in JSON: FAIL (0.04s) *** Failed! Falsifiable (after 1 test): Event {_severity = Error, _facility = Unspecified, _sampled = 1894-02-22 00:00:04.5986 UTC, _eventDetails = ElementDisconnect {_elementMAC = 8ec52584b2c82424}, _eventMessage = Nothing, _originator = http://www.ietf.org/rfc/rfc2396.txt, _reference = Just http://www.ietf.org/rfc/rfc2396.txt }

slide-37
SLIDE 37

Event roundtrips in JSON: FAIL (0.04s) *** Failed! Falsifiable (after 1 test): Event {_severity = Error, _facility = Unspecified, _sampled = 1894-02-22 00:00:04.5986 UTC, _eventDetails = ElementDisconnect {_elementMAC = 8ec52584b2c82424}, _eventMessage = Nothing, _originator = http://www.ietf.org/rfc/rfc2396.txt, _reference = Just http://www.ietf.org/rfc/rfc2396.txt }

slide-38
SLIDE 38

ghci> t 1894-02-22 00:00:04.5986 UTC ghci> Data.Aeson.encode t "\"1894-02-22T00:00:04.598Z\""

slide-39
SLIDE 39

build deploy monitor test develop

slide-40
SLIDE 40

postgresql-transactional

github.com/helium/postgresql-transactional

slide-41
SLIDE 41

lookupUser emailAddress = queryFirst [emailAddress] [sql| SELECT id, email, name, timezone FROM user_account
 WHERE email = ? |]

slide-42
SLIDE 42

foo

slide-43
SLIDE 43

foo bar

slide-44
SLIDE 44

foo bar baz

slide-45
SLIDE 45

foo bar baz quz

slide-46
SLIDE 46

foo bar baz quz buz

slide-47
SLIDE 47

foo bar baz quz buz fiz

slide-48
SLIDE 48

BEGIN BEGIN COMMIT COMMIT

slide-49
SLIDE 49

BEGIN BEGIN COMMIT COMMIT

slide-50
SLIDE 50

BEGIN BEGIN COMMIT COMMIT

slide-51
SLIDE 51

WARNING: there is already a transaction in progress WARNING: there is no transaction in progress

slide-52
SLIDE 52

foo bar baz quz buz fiz

slide-53
SLIDE 53

foo bar baz quz buz fiz

slide-54
SLIDE 54

foo bar baz quz buz

slide-55
SLIDE 55

lookupUser :: Connection -> Text -> IO (Maybe User) lookupUser connection emailAddress = queryFirst [emailAddress] [sql| SELECT id, email, name, timezone FROM user_account
 WHERE email = ? |] connection

slide-56
SLIDE 56

createUser :: Connection

  • > NewUser
  • > IO User

createOrganization :: Connection

  • > NewOrganization
  • > IO Organization

addUserToOrganization :: Connection

  • > User
  • > Organization
  • > IO ()
slide-57
SLIDE 57

createUserAndOrganization :: Connection

  • > NewUser
  • > IO ()

createUserAndOrganization connection newUser = withTransaction connection $ do let newOrganization = NewOrganization (newUser ^. name) user <- createUser connection newUser

  • rg <- createOrganization connection newOrganization

addUserToOrganization connection user org

slide-58
SLIDE 58
  • - NOTE: you MUST wrap this in a transaction!!

createUserAndOrganization :: Connection

  • > NewUser
  • > IO ()

createUserAndOrganization connection newUser = do let newOrganization = NewOrganization (newUser ^. name) user <- createUser connection newUser

  • rg <- createOrganization connection newOrganization

addUserToOrganization connection user org

slide-59
SLIDE 59

withTransaction conn $ do createUserAndOrganization conn newUser somethingElse conn

slide-60
SLIDE 60

types to the rescue

slide-61
SLIDE 61

lookupUser :: Connection -> Text -> IO (Maybe User) lookupUser :: Text -> PGTransaction (Maybe User)

slide-62
SLIDE 62

runPGTransaction :: PGTransaction a

  • > Postgres.Connection
  • > IO a
slide-63
SLIDE 63

createUserAndOrganization :: NewUser

  • > PGTransaction ()

createUserAndOrganization newUser = let newOrganization = NewOrganization (newUser ^. name) user <- createUser newUser

  • rg <- createOrganization newOrganization

addUserToOrganization user org foo = do createUserAndOrganization newUser somethingElse runPGTransaction foo connection

slide-64
SLIDE 64

notAllowed = do user <- createUser newUser someSlowSideEffectingThing return user

slide-65
SLIDE 65

notAllowed = do user <- createUser newUser someSlowSideEffectingThing :: IO () return user

slide-66
SLIDE 66

postgresql-transactional

github.com/helium/postgresql-transactional

slide-67
SLIDE 67

build deploy monitor test develop

slide-68
SLIDE 68

Reid Draper @reiddraper github.com/helium helium.com