Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When your express app gets a request to edit the config, add an item to an <a href="https://caolan.github.io/async/docs.html#queue" rel="nofollow noreferrer">async.js queue</a> configured with concurrency of 1. This will prevent > 1 concurrent attempt to edit the remote configuration. Pseudo code would be:</p> <ul> <li>at app startup, define your <code>updateNetworkConfig</code> function</li> <li>at app startup, create a queue of concurrency 1 <ul> <li><code>var networkQueue = async.queue(updateNetworkConfig, 1);</code></li> </ul></li> <li>REST comes in like PUT /api/config/network with the new config as the request body in JSON</li> <li>Add an item to the queue, passing along the new config data <ul> <li><code>networkQueue.push(req.body.config);</code></li> <li>(<code>req.body</code> provided by the bodyParser connect middleware)</li> </ul></li> <li>Repeat that setup for each independent config: filesystem, etc</li> </ul> <p>You'll need a bunch of other plumbing to deal with callbacks and notify the REST clients when their configuration has been saved. Up to you whether to queue up calls or reject new calls if the queue is not empty.</p> <p>Since you insist on not learning and using the awesome async.js library that will increase your fluency with asynchronous programming and teach you valuable things, here's the deal. Use this thing called a variable.</p> <pre><code>var updatingNetwork = false; app.put('/api/config/network', function (req, res) { if (updatingNetwork) { return res.status(409).send("Try later"); } updatingNetwork = true; updateNetworkConfig(req.body.config, function (error) { updatingNetwork = false; if (error) { return res.status(500).send(error); } res.status(200).send("done"); }); }); </code></pre> <ul> <li>When a request comes in, if <code>updatingNetwork</code> is true, you know there's already an update in process, either queue this one up or reject it.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload