dokuzbir

dokuzbir

Unique Identifier For Session

I have a slot booking app. What i want is lock a slot 5 minutes for a session/user. I added lock_until, locked_for attributes to slots. A user has id, but what is equivalent thing for a session. Also if there are another approaches can you please share?

Marked As Solved

NobbZ

NobbZ

The trick with such identifiers is, that you can use whatever you like and write it into the session…

I’m not experienced with phoenix, but have you considered using it roughly like this?

def create_token() do
  uuid = UUID.generate_v4() # you probably need to get a UUID package, therefore this is pseudo code
  Phoenix.Token.sign(YourApp.Endpoint, "your secret salt", uuid)
end

def validate_token(token) do
  Phoenix.Token.verify(YourApp.Endpoint, "your secret salt", token, max_age: 5 * 60)
end

You can store and retrieve that Token via Plug.Conn.{fetch,get,put}_session.

Also Liked

kokolegorille

kokolegorille

There is a slot locking mecanism in this video

around 25 minutes… If this is what You are looking for.

Basically You want to lock a slot for a booking application for 5 minutes? Probably because each booking reduces the capacity of your stock, and You don’t want to sell more than what You can provide.

He wants to lock a timeslot for a user to order something, so no other user could bypass this by typing faster. There is not even the need to store lock_until, just spawn a process with locked_for, and a timeout. As soon as the process expire, so does the lock.

Each resource has a capacity, when You want to book, You request an access, that will decrement capacity, in case You don’t fill the booking in 5 minutes, the token expires without being used, and capacity is increased.

Is that what You want to do?

mgwidmann

mgwidmann

I’m not sure what a slot booking app is, could you clarify what you’re trying to do a bit more? Are you trying to ensure a user in a Phoenix application gets logged out every 5 minutes?

Qqwy

Qqwy

TypeCheck Core Team

Instead of using an UUID, you could use make_ref() |> :erlang.term_to_binary() to create a string-representation of an almost surely unique reference (The keyspace is 2^82), whose behaviour is provided to you by the Erlang VM.

Where Next?

Popular in Questions Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

We're in Beta

About us Mission Statement