Add a few lingering changes to the Mu voting example

Some of this is out of date, however I'm archiving work in progress,
and will freshen it up momentarily.
This commit is contained in:
joeduffy 2016-11-01 10:31:21 -07:00
parent 8c3dbf9d6d
commit d6b2575008
4 changed files with 14 additions and 8 deletions

View file

@ -1,3 +1,7 @@
# TODO(joe): Docker Swarm vs. Kubernetes vs. ECS.
# TODO(joe): Get conflicted on AWS Lambda passthrough vs. our own scheduler.
# TODO(joe): Terraform vs. CloudFormation; applying diffs may be harder w/ CF.
# TODO(joe): parameterize? (e.g., environment "prod" vs "stage" vs ...)
# TODO(joe): we are inferring "names" from variable assignments; should constructors require names?
# TODO(joe): schema for RPCs is currently weakly typed (because this is a JS example).
@ -8,3 +12,4 @@
# TODO(joe): how to export resources for consumption in app.template?
# TODO(joe): should we use descriptions, etc.?

View file

@ -67,7 +67,7 @@ Resources:
Ref: CodeBucket
S3Key:
Ref: CodeObjectKey
Runtime: nodejs
Runtime: nodejs4.3
Handler: app.services.voting.trigger
Role:
!GetAtt:

View file

@ -1,7 +1,7 @@
name: voting
type: Service
api: ./voting.proto
resources:
services:
votes: mu.services.Table
voteCounts: mu.services.Table
votesFunction: mu.Function

View file

@ -1,10 +1,11 @@
var mu = require("mu");
// Define a Service that creates a Stack, wires up Functions to Triggers, and exposes an API:
class VotingService {
class VotingService extends mu.Service {
constructor() {
this.votes = new mu.Table();
this.voteCounts = new mu.Table();
super();
this.votes = new mu.services.Table();
this.voteCounts = new mu.services.Table();
this.votes.forEach(vote => {
// Keep our aggregated counts up-to-date:
this.voteCounts.updateIncrement(vote.color, vote.count);
@ -17,10 +18,10 @@ class VotingService {
}
// Create a HTTP endpoint Service that receives votes from an API:
var voteAPI = new mu.HTTPGateway();
var voteAPI = new mu.services.HTTPGateway();
for (var state of [ "AL", "AK", ... "WI", "WY" ]) {
for (var state of [ "AL", "AK", /*...,*/ "WI", "WY" ]) {
var votingService = new VotingService();
voteAPI.register(`/${state}`, votingService);
voteAPI.register(`/${state}/vote`, votingService);
}