Get furnace to load again
parent
cc600ad54f
commit
268dfaeec9
|
@ -57,17 +57,9 @@ SYMBOL: validation-errors
|
|||
] if*
|
||||
] with map ;
|
||||
|
||||
: expire-sessions ( -- )
|
||||
sessions get-global
|
||||
[ nip session-last-seen 20 minutes ago <=> 0 > ]
|
||||
[ 2drop ] heap-pop-while ;
|
||||
|
||||
: lookup-session ( hash -- session )
|
||||
"furnace-session-id" over at sessions get-global at [
|
||||
nip
|
||||
] [
|
||||
new-session rot "furnace-session-id" swap set-at
|
||||
] if* ;
|
||||
"furnace-session-id" over at get-session
|
||||
[ ] [ new-session "furnace-session-id" roll set-at ] ?if ;
|
||||
|
||||
: quot>query ( seq action -- hash )
|
||||
>r >array r> "action-params" word-prop
|
||||
|
|
|
@ -1,37 +1,48 @@
|
|||
USING: assoc-heaps assocs calendar crypto.sha2 heaps
|
||||
init kernel math.parser namespaces random ;
|
||||
USING: assocs calendar init kernel math.parser
|
||||
namespaces random boxes alarms ;
|
||||
IN: furnace.sessions
|
||||
|
||||
SYMBOL: sessions
|
||||
|
||||
: timeout ( -- dt ) 20 minutes ;
|
||||
|
||||
[
|
||||
H{ } clone <min-heap> <assoc-heap>
|
||||
sessions set-global
|
||||
H{ } clone sessions set-global
|
||||
] "furnace.sessions" add-init-hook
|
||||
|
||||
: new-session-id ( -- str )
|
||||
4 big-random number>string string>sha-256-string
|
||||
dup sessions get-global at [ drop new-session-id ] when ;
|
||||
4 big-random >hex
|
||||
dup sessions get-global key?
|
||||
[ drop new-session-id ] when ;
|
||||
|
||||
TUPLE: session created last-seen user-agent namespace ;
|
||||
TUPLE: session id namespace alarm user-agent ;
|
||||
|
||||
M: session <=> ( session1 session2 -- n )
|
||||
[ session-last-seen ] 2apply <=> ;
|
||||
: cancel-timeout ( session -- )
|
||||
session-alarm ?box [ cancel-alarm ] [ drop ] if ;
|
||||
|
||||
: <session> ( -- obj )
|
||||
now dup H{ } clone
|
||||
[ set-session-created set-session-last-seen set-session-namespace ]
|
||||
\ session construct ;
|
||||
: delete-session ( session -- )
|
||||
sessions get-global delete-at*
|
||||
[ cancel-timeout ] [ drop ] if ;
|
||||
|
||||
: new-session ( -- obj id )
|
||||
<session> new-session-id [ sessions get-global set-at ] 2keep ;
|
||||
: touch-session ( session -- )
|
||||
dup cancel-timeout
|
||||
dup [ session-id delete-session ] curry timeout later
|
||||
swap session-alarm >box ;
|
||||
|
||||
: get-session ( id -- obj/f )
|
||||
sessions get-global at* [ "no session found 1" throw ] unless ;
|
||||
: <session> ( id -- session )
|
||||
H{ } clone <box> f session construct-boa ;
|
||||
|
||||
! Delete from the assoc only, the heap will timeout
|
||||
: destroy-session ( id -- )
|
||||
sessions get-global assoc-heap-assoc delete-at ;
|
||||
: new-session ( -- session id )
|
||||
new-session-id [
|
||||
dup <session> [
|
||||
[ sessions get-global set-at ] keep
|
||||
touch-session
|
||||
] keep
|
||||
] keep ;
|
||||
|
||||
: get-session ( id -- session/f )
|
||||
sessions get-global at*
|
||||
[ dup touch-session ] when ;
|
||||
|
||||
: session> ( str -- obj )
|
||||
session get session-namespace at ;
|
||||
|
|
Loading…
Reference in New Issue