0.0
No commit activity in last 3 years
No release in over 3 years
This gem adds polling_request Javascript assets to Rail's asset pipeline
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

>= 3.0
 Project Readme

Polling Request Build Status

jQuery helper object for AJAX polling a progress-aware endpoint.

Usage

req = new PollingRequest
  url: "/states.csv"
  interval: 1000   # polling interval in milliseconds
  progress: (n)->
    console.log "Progress: #{n} percent"
  success: (res)->
    console.log "Response body: #{res}"
  error: (status, response)->
    console.log("Status: #{status}, Body: #{response}")
  complete: (status, response)->
    console.log("This is called after everything else")

req.status   # 'pending'
req.start()
req.status   # 'running'
req.progress # 0

# sometime later
req.status   # 'running'
req.progress # 50

# much later
req.status   # 'success'
req.progress # 100

# example of setting a hard timeout
setTimeout ->
  req.stop()
, 5000

Progress Aware Endpoint

PollingRequests will have a header X-POLLING-REQUEST set. It expects an HTTP endpoint to respond with a 202 Accepted status code when there is more processing to be done. The JSON response body can optionally include a progress property whose value is an integer 0..100 inclusive to indicate the percentage of processing completed.

$ curl -i http://localhost/endpoint
HTTP/1.1 202 Accepted
{ progress: 0 }

$ curl -i http://localhost/endpoint
HTTP/1.1 202 Accepted
{ progress: 50 }

$ curl -i http://localhost/endpoint
HTTP/1.1 200 Success
Content-Type: text/plain
Successful responses can be any content type

Rails

To access PollingRequest from the asset pipeline, add the following to your Gemfile:

gem 'polling_request'

And this to your asset manifest:

//= require polling_request

Bower

PollingRequest is in the Bower registry. JavaScript and CoffeeScript sources are included.

$ bower install polling-request

Development

Dependencies are managed by npm and Bower.

$ npm install
$ bower install

Tests are written with QUnit and can be run in a browser by opening test/test.html. Continuous integration is run with phantomjs:

$ ./node_modules/phantomjs/lib/phantom/bin/phantomjs test/runner.js test/test.html

Wish List

  • Better docs for building and installing project

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request