Comments (7)
@michelson when in doubt, always add a catch all and see what it looks like:
receive do
whatever -> IO.inspect whatever
end
:)
from phoenix_pubsub.
Can you add {:ok, _} = Code.ensure_loaded(Enumerable.MapSet)
to def start/2
in your application callback (usually in "lib/my_app.ex") and let us know if the error disappears?
Also please double check you are running in production environment.
This is not a Phoenix bug per se. We have had reports of something similar happening but we could not yet reproduce it.
from phoenix_pubsub.
Hello @josevalim ,
thanks for your quick reply, I've tunned some sysctl settings on my machine and this error disappeared among other errors.
Also note that I'm using this plugin with a mix application, not a phoenix application. it seems This kinds of errors are raised when process reaches system limits on file descriptors
I'm trying to implement a long polling application which each request is tracked with Tracker and each req starts a PubSub subscriber, if subscriber got message the response is released to the client. (i'm using task async/yield which blocks requests until got response)
I would like to know if this is the correct way to do it, it will scale well ?
get "/api/process/:key" do
key2 = key |> String.replace(".json", "")
Phoenix.Tracker.track(Notify.Tracker, self(), "devices", key2, %{stat: "CONNECTED"})
proc = self()
Phoenix.PubSub.subscribe Notify.PubSub, key2
task = Task.Supervisor.async_nolink(NotifyWeb.TaskSupervisor, fn ->
try do
check_process(proc)
catch
:exit, _ -> {:error}
end
end)
conn = put_resp_header(conn, "content-type", "application/json")
# await for task to return, will also return exit process
case Task.yield(task, 60000) do
[] -> send_resp(conn, 200, "[]")
{:ok, res3} ->
case res3 do
{:ok, [actions: str]} -> deliver_actions(key2, conn, 200, str)
{:ok, _} -> send_resp(conn, 200, "[]")
end
{:exit, _} -> send_resp(conn, 200, "[]")
{:error, _} -> send_resp(conn, 200, "[]")
nil -> send_resp(conn, 200, "[]")
_ -> send_resp(conn, 200, "[]")
end
end
def deliver_actions(key, conn, status, str) do
send_resp(conn, status, str)
end
# recursive function to respond when got data
def check_process(proc) do
:timer.sleep(1000)
case Process.info(proc)[:messages] do
[] -> check_process(proc)
{:ok, [actions: res]} -> {:ok, [actions: res]}
val -> check_process(proc)
end
end
from phoenix_pubsub.
thanks for your quick reply, I've tunned some sysctl settings on my machine and this error disappeared among other errors.
Good call.
I would like to know if this is the correct way to do it, it will scale well ?
Using Process.info(prod)[:messages]
and :timer.sleep(1000)
are usually a no-no. You want the task process to instead send you a message instead of looking into its inbox at every time interval.
In fact, it seems like you don't need the task at all. You can subscribe directly from the request process and use receive
to await for the message and use after
for timeout.
from phoenix_pubsub.
Thanks José , I will investigate how can I implement that
best regards
from phoenix_pubsub.
You can subscribe directly from the request process and use receive to await for the message and use after for timeout.
having this Process.info(self)[:messages]
to read messages, how can I use receive
to listen for new messages ?
I'm trying this:
Phoenix.PubSub.subscribe Notify.PubSub, key
receive do
{:ok, [actions: res]} -> deliver_actions(key, conn, res)
{msg} -> IO.inspect msg
after
60_000 -> send_resp(conn, 200, "[d]")
end
but I only get the after
response
from phoenix_pubsub.
forget it , It was my mistake on the match handling
thanks
from phoenix_pubsub.
Related Issues (20)
- Optimize pool_size of 0 for PG2 to allow publisher only operation
- Latest Version of Phoenix.PubSub in Hex HOT 1
- broadcast_from!/4 is undefined or private HOT 1
- Network traffic up for 20 minutes after a server restart
- Release v1.1.3 suppressing warnings HOT 1
- Where is version 2.0? HOT 1
- It may be helpful for users, if parallel option can be provided when starting Registry. Without it partitions in registry executes sequentially. HOT 1
- unknown registry: XXX.PubSub HOT 4
- RFC: Provide a way to mass update presences HOT 1
- topic forced to be string HOT 1
- Race condition causing data inconsistency when nodes are coming up
- Does Phoenix.PubSub itself support subscribing to wildcard topics? HOT 1
- PubSub registry fails to start or race condition when testing? HOT 3
- [Feature Request] Be able to transform a module into a Pub.Sub HOT 6
- Unsubscribe all HOT 2
- v2.1 and v2.0 are incompatible
- Odd Jason Encoding error after new release HOT 2
- Broken Build Status link
- Presence list keep growing when using Presence.update HOT 3
- Presence stops working after ~1 week HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phoenix_pubsub.