Running well
Seven habits
Section titled “Seven habits”What keeps a wisp quick and cheap, for you and for the servers it is in, most important first:
- Ask for the items you use. Every item is events your wisp handles. A dice wisp needs Post and Commands and hears nothing; a welcome wisp needs Members, not Messages.
- Hear, don’t poll. An event reaches your wisp the moment it happens. Reading history on a timer spends your limits to learn what your wisp was already told.
- Keep its place (below). A restart then picks up where it left off, instead of reading to catch up.
- Change parts, not cards. Key what moves and send a patch. For motion, send live frames: only the newest of a burst goes out, and nothing is stored. A countdown needs nothing at all: its mark counts in the app.
- Answer, then work. Answer a run at once and edit your line when slow work is done.
- Keep handlers short. A slow event handler holds up that server’s next events. Hand long work to a queue of your own.
- Let the library pace you. Add no delays of your own: calls to many channels flow, and lines into one channel take their turn.
Limits
Section titled “Limits”Woosh gives every wisp limits, and the library keeps to them for you, waiting a moment when one is reached rather than failing. As your wisp starts they are, in short:
| Limit | |
|---|---|
| Calls | 100 a second, with bursts up to 500 |
| One server | 50 calls a second |
| One channel | 5 new lines a second |
| One line’s edits | 4 a second; live frames in between are dropped for the newest |
Answers to runs and presses are paid for by the person who ran or pressed, so a busy command never eats into your limits. The numbers your wisp gets are the ones Woosh tells it as it connects.
Keeping your place
Section titled “Keeping your place”Give the library somewhere to keep its place, and a restart or a deploy misses nothing said within 10 minutes:
var options = WispOptions.FromEnvironment() with{ CursorFile = "wisp-cursor.json",};await using var wisp = new WispClient(options);Or give it your own ICursorStore, such as a row in your database.
const wisp = new Wisp({ id: process.env.WISP_ID!, secret: process.env.WISP_SECRET!, cursor: "wisp-cursor.json",});Or give cursor a store of your own, with load and save, such as a row in your database.
Left out, the place is kept in memory: a drop misses nothing, but a restart starts afresh. The place moves past an event only once every handler has finished with it, so after a crash the events that were being handled come again: make handling one twice harmless. Woosh never lets a run take two answers.
Each time your wisp is connected, at the start and after every reconnect, it hears that its line is
ready (LineReady; in TypeScript, lineReady). When it says events were missed, it was away longer
than 10 minutes: read what you need and carry on (Reading what came
before).
Deploying without a gap
Section titled “Deploying without a gap”Start the new process with the same place kept. When its line is ready, tell the old one to hand over:
await oldWisp.HandOverAsync(); // finishes what it owes, then lets goawait oldWisp.handOver(); // finishes what it owes, then lets goPeople never see your wisp go offline.
When things go wrong
Section titled “When things go wrong”| Thrown | When |
|---|---|
ArgumentException |
a command, option, card or form that breaks a rule, before anything is sent |
WispCallException with Refused |
Woosh said no. Why says why (Acting in a server). Not retried |
WispCallException with Limited |
only when a call could not get through within 30 seconds; Budget names the limit |
WispCallException with Failed |
it may or may not have run, and retrying for 30 seconds did not settle it |
WispFatalException |
from RunAsync: the secret is wrong or was reset |
Logs go to the ILoggerFactory you give it, under Woosh.Wisp.
| Thrown | When |
|---|---|
WispRuleError |
a command, option, card or form that breaks a rule, before anything is sent |
WispCallError with code "refused" |
Woosh said no. why says why (Acting in a server). Not retried |
WispCallError with code "limited" |
only when a call could not get through within 30 seconds; budget names the limit |
WispCallError with code "failed" |
it may or may not have run, and retrying for 30 seconds did not settle it |
WispFatalError |
from start(), or later from wisp.stopped: the secret is wrong or was reset |
Logs go to the console, each line starting with wisp:, or to the logger you give it.
- A call made while the connection is down waits for it to come back, within the same 30 seconds.
- A run or a press that arrives after its 15 seconds, after a reconnect, is passed over: it can no longer be answered.
Nothing a person typed is logged.