1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
This is a silly little example that shows how you
can use AnyEvent::WebSocket::Client.
- jobserver is a Mojolicious::Lite app (also requires Mojo::Redis2
and a redis server running on localhost) that cordinates and
displays job output.
- jobrunner is an AnyEvent::WebSocket::Client program that runs a
program locally and sends the output as events via WebSocket
to jobserver.
- slowlast is just a program that runs `last -30` very slowly so
that you can see the output update on the server.
- jobviewer is an AnyEvent::WebSocket::Client program that attaches
to the jobserver and displays a job as it is running via
WebSockets.
There are probably a few bugs and race conditions (in particular
events may be missing for currently running jobs in the webapp
or from the jobviewer) and there are probably better ways to do
this sort of thing, but it demonstrates the library so there it
is.
Instructions:
- install the prereqs if they aren't there:
% cpanm --installdeps .
- start redis (if it isn't already started):
% redis-server
- start the jobserver
% ./jobserver daemon
- in another window run a slow running process that produces
some output, you can use slowlast as an example that comes
with this distro
% ./jobrunner ./slowlast
- in your web browser, go to the jobserver url and navigate
to the slow running process. You should see the existing
output, plus any new output as it gets sent through the
job server.
http://localhost:3000
- in another window (again!) you can use jobviewer to watch
a job in process:
% jobviewer
... lists jobs managed by jobserver
% jobviewer 1234:1
... watch job 1234:1
|