CrowdHailer / raxx

Interface for HTTP webservers, frameworks and clients
https://hexdocs.pm/raxx
Apache License 2.0
401 stars 29 forks source link

Add a functionality to set a date on responses. #105

Closed CrowdHailer closed 5 years ago

CrowdHailer commented 6 years ago

Because looking up the time can be relatively expensive, we should not look it up for every request.

I suggest having a process that writes the date to an ets table every second. and other processes can read from this table to set the value in a response. This is how I think cowboy does it.

  1. To start the writing process something like this should be added to the application supervision tree

    {Raxx.Date, [interval: 1_000]}

    This creates a named ets table called :"raxx.date"and writes to it every second

  2. The current date can be explicitly written to a response as follows

    Raxx.set_date(response) 

    This looks up date from :"raxx.date"

  3. Calls to set_date can be wrapped up in a middleware. use Raxx.Date that can be added to router/controller

varnerac commented 6 years ago

Is there an init call for middleware that’s called at server startup to allow us to start the supervisor and gen_server?

CrowdHailer commented 6 years ago

Raxx is just a library not an application. so there is no supervision tree to add it to.

Ace has a supervision tree but I would like it to be separate from raxx middleware

varnerac commented 6 years ago

The date functionality needs a supervisor. Perhaps this goes in Ace?

CrowdHailer commented 6 years ago

I don't see why explicitly adding a supervisor would be much of a problem.

There could be a raxx_date application that is not a library. which has it's own supervision tree but that seams rather to small a project to be standalone

CrowdHailer commented 5 years ago

Removed as not blocking anyone at the moment.

Waiting for a standard middleware format, or opinionatedly can just be handled in the server layer