[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: http-request in a controller- is it possible?

From: Jaft
Subject: Re: http-request in a controller- is it possible?
Date: Fri, 4 Dec 2020 18:00:23 +0000 (UTC)

I'm not sure if this is related (so I may be entirely incorrect here) but I tried, while running with Ragnarok, adding (sleep 20) to one of the endpoints in a controller and tried loading the endpoint.

Throughout the duration of that 20 seconds, trying to load any other endpoint for the Artanis instance hung until the sleep function finished (and, I assume, the rest of the Guile code for the endpoint finished before running the other endpoints).

I know Ragnarok is supposed to be non-blocking so should this be the case? Or, heh, is this expected behavior and I'm just misunderstanding how things work?


On Thursday, December 3, 2020, 11:48:36 AM CST, Nala Ginrut <> wrote:

BTW, if you really want to call http-get at present, you may need to set the
port to non-blocking manually:
(import (web client))

(lambda (rc)
(define port (open-socket-for-uri "http://localhost:3000/123"))
(fcntl port F_SETFL (logior O_NONBLOCK (fcntl port F_GETFL 0)))
(lambda () (http-get "http://localhost:3000/123" #:port port))
(lambda (res body) body))))

This works for me.

Best regards.

Nala Ginrut writes:

> I've tested it, guile internal server-core doesn't work too.
> So I believe Artanis has to implement its own client API to make it
> work.
> The client API is necessary, since people may need to make OAUTH.
> I'll add it to TODO.
> Best regards.
> Nala Ginrut writes:
>> Hi Morimer!
>> In theory, the API of (web client) like http-get should work in Ragnarok.
>> Because Ragnaork based on suspendable-ports for co-routine, and when
>> suspendable-ports is enabled, all the I/O ports defined in Guile should
>> be affected to be non-blocking.
>> I'm not sure about http-request function, where did you find it?
>> Anyway, if you don't insist on non-blocking, you can use guile
>> server-core to avoid non-blocking issue:
>> ------------------------cut-----------------------
>> art work -s guile
>> ------------------------end-----------------------
>> Best regards.
>> Mortimer Cladwell writes:
>>> Hi,
>>> Given the controller:
>>> (register-define add
>>>  (lambda (rc)
>>>  (let* (
>>>          ;;(btc-usd 18000)
>>>            (btc-usd (string->number(receive (response-status response-body)
>>>                                    (http-request "
>>>") response-body)))
>>>          (btc-req (/ 5000 btc-usd))
>>>                (currency-content (string-append " <option
>>> value=\"btc\">Bitcoin " (number->string btc-req) " BTC</option>)))
>>>  (view-render "add" (the-environment)))
>>>  ))
>>> If I navigate to the browser hangs and
>>> eventually times out.
>>> At the console:
>>> Ragnarok: continue request
>>> Error: (wrong-type-arg #f Wrong type (expecting ~A): ~S (resumable
>>> continuation #<vm-continuation 7f768042f930>) (#<vm-continuation
>>> 7f768042f930>))
>>> Ingore it to avoid Ragnarok crash.
>>> main-loop again
>>> If at the REPL I evaluate (string->number (receive (response-status
>>> response-body)
>>>      (http-request "") response-body))
>>> I get a number e.g 18,123.45
>>> If I comment out (btc-usd (string->number(receive.... ) and uncomment
>>> (btc-usd 18000), the expected page is rendered properly.
>>> Is it possible to use (http-request... ) in a controller?
>>> If not is there a workaround?
>>> Thanks
>>> Mortimer

GNU Powered it
GPL Protected it
GOD Blessed it
HFG - NalaGinrut
Fingerprint F53B 4C56 95B5 E4D5 6093 4324 8469 6772 846A 0058

reply via email to

[Prev in Thread] Current Thread [Next in Thread]