Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Wang Ling committed May 21, 2012
1 parent 7ac4a2a commit 5e7be87
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
1 change: 0 additions & 1 deletion Makefile
Expand Up @@ -10,7 +10,6 @@ build:
@NODE_ENV=build mkdir -p lib/web
@cp src/web/fairy.html lib/web/fairy.html
@cp src/web/fairy.css lib/web/fairy.css
@cp src/web/fairy_active.js lib/web/fairy_active.js
@coffee -c$(opt) -o lib src
test:
@rm -f test/workers/*.dmp
Expand Down
2 changes: 1 addition & 1 deletion example/app.coffee
Expand Up @@ -3,7 +3,7 @@ express = require 'express'
fairy_web = require '../web'

app = express.createServer()
app.use fairy_web.middleware
app.use fairy_web.connect().middleware
app.listen 8765

console.log "'fairy-web' is running at http://0.0.0.0:8765"
57 changes: 31 additions & 26 deletions src/server.coffee
Expand Up @@ -10,32 +10,37 @@ singular_commands =
get: ['statistics', 'recently_finished_tasks', 'failed_tasks', 'slowest_tasks', 'processing_tasks', 'workers']
post:['reschedule', 'clear']

exports.__defineGetter__ 'middleware', ->
fairy = require('../.').connect()
for method, commands of plural_commands
for command in commands
router.route method, "/api/queues/#{command}", no_cache, do (command) ->
(req, res) ->
fairy[command] (err, results) ->
return res.send 500, err.stack if err
res.send results
exports.connect = (options = {}) ->
new Connect(options)

for method, commands of singular_commands
for command in commands
router.route method, "/api/queues/:name/#{command}", no_cache, do (command) ->
(req, res) ->
queue = fairy.queue req.params.name
queue[command] (err, results) ->
return res.send 500, err.stack if err
res.send results

(req, res, next) ->
router.middleware req, res, ->
req.url = '/fairy.html' if req.url is '/fairy'
staticCache req, res, ->
static_ req, res, next
class Connect
constructor: (@options) ->
@fairy = require('../.').connect(options)
@no_cache = (req, res, next) ->
res.setHeader "Cache-Control", "no-cache"
next()
@__defineGetter__ 'middleware', =>
for method, commands of plural_commands
for command in commands
router.route method, "/api/queues/#{command}", @no_cache, do (command) =>
(req, res) =>
@fairy[command] (err, results) ->
return res.send 500, err.stack if err
res.send results

for method, commands of singular_commands
for command in commands
router.route method, "/api/queues/:name/#{command}", @no_cache, do (command) =>
(req, res) =>
queue = @fairy.queue req.params.name
queue[command] (err, results) ->
return res.send 500, err.stack if err
res.send results

(req, res, next) ->
router.middleware req, res, ->
req.url = '/fairy.html' if req.url is '/fairy'
staticCache req, res, ->
static_ req, res, next

no_cache = (req, res, next) ->
res.setHeader "Cache-Control", "no-cache"
next()

1 change: 0 additions & 1 deletion src/web/fairy.html
Expand Up @@ -237,6 +237,5 @@ <h1><span>Fairy Statistics</span></h1>
<script src="https://raw.github.com/timrwood/moment/1.6.2/moment.js" type="text/javascript"></script>
<script src="fairy.js" type="text/javascript"></script>
<script type="text/javascript">window.id = new id_factory()</script>
<script src="fairy_active.js" type="text/javascript"></script>
</body>
</html>

0 comments on commit 5e7be87

Please sign in to comment.