On 12/21/2019 4:44 AM, Marc Kaufmann wrote:
one useful feature of the Django web framework is that it is easy to access the database and change it on the fly. I am not using a DB, but a hash inside of Racket for various reasons. I understand that it would be easy to connect to a database in any language, and getting the hash is a different beast - but I am wondering if there is an easy way such that I could tell the racket web server via a command line or REPL interaction "(update-user uid key-name new-value)" or some such.

Is that easily possible? (And very secondarily: Is this a stupid idea? But even if it is, it's what I am under time pressure to get working, as a proper solution ain't gonna happen in time.)

Running a REPL inside your program is fairly easy but not terribly safe.  E.g., you can dedicate a thread to reading a network port and executing whatever code fragments you send.  But you need to take precautions, limiting what it is allowed to do, and who can access it, so unauthorized users can't screw up your program.

In my apps I make hot tweak settings available through a secured web interface.  The "variables" are functions exported from my configuration module (similar to the way parameters work).

   (define-syntax getter/setter!
      (syntax-rules ()
        ((getter/setter!)
         ; -- start template

         (let [(var null)]
           (lambda x
             (cond
               ([null? x] var)
               ([pair? x] (set! var (car x)))
               (else (error))
               ))
           )

         ; -- end template
         )))

   (define some-config-var (getter/setter!))


Then /(some-config-var <value>)/  changes the value, and /(some-config-var)/  gets the current value.

It's simplistic, but it works well.  I haven't run into the need for more explicit synchronization, but if needed it would be simple to add a semaphore / mutex to the macro.

During program execution I can tweak these "variables" using a special HTML page that lets me review and set many variables all at once.  But it could be done using a bunch of simple handlers - one per variable - that could be command line driven using curl.


In your case, you could create an "update-user" URL handler that updates your hash from its arguments.  If you give it an hard to guess name and don't document it, then it may be reasonably safe.

YMMV,
George

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/b3a4de57-9b40-faa3-651b-b5efa08329a4%40comcast.net.

Reply via email to