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