Sugar is a server side event notification system to deliver event data payloads to subscribed clients. By default it will attempt to connect the client to the server using websockets and will fall back to long polling.
See https://github.com/zooniverse/Sugar-Client for the client implementation details.
The server is a wrapper around Redis pub/sub (https://redis.io/topics/pubsub) and real time events (https://github.com/primus/primus#engineio) connections all via a HTTP API.
The HTTP end points are:
get '/presence'
get '/active_users?channel=zooniverse'
post '/notify'
post '/announce'
post '/experiment'
All requests to the post end points must include a formatted message body for the matching event type as described below.
The 3 types of messages the system accepts are:
{"notifications": [{"user_id": "1", "message": "Hiya", "url": "test", "delivered": "false"}]}
{"announcements": [{"message": "announcment message", "url": "test", "section": "zooniverse", "delivered": "false"}]}
{"experiments": [{"user_id": "1", "message": "would you like to participate?", "url": "test", "delivered": "false"}]}
Construct per user notification payloads in JSON and use something like cURL to POST the payload to the notifications server. E.g.
curl -vv \
-X "POST" "https://notifications-staging.zooniverse.org/notify" \
-H 'Content-Type: application/json' \
-u 'username:password' \
-d $'{
"notifications": [{
"message": "A message from curl to user 1",
"user_id": "1",
"url": "http://test.net",
"delivered": false
}]
}'
Visit https://notifications-staging.zooniverse.org/ for debug user & testing section announcements and user notifications.
To Run a local version of the sugar system
docker-compose builddocker-compose upRun run the tests (you may need to rebuild the docker image if the src changes)
docker-compose run -T --rm sugar npm testGet a bash container via docker to run tests, etc
docker-compose run --rm sugar bash
Content type
Image
Digest
sha256:69b9005a6…
Size
57.2 MB
Last updated
over 4 years ago
docker pull zooniverse/sugar