Skip to content

Instantly share code, notes, and snippets.

@princesspretzel
Created December 13, 2017 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save princesspretzel/cee58b0a426adbeb0b1d2ef5da5cbc17 to your computer and use it in GitHub Desktop.
Save princesspretzel/cee58b0a426adbeb0b1d2ef5da5cbc17 to your computer and use it in GitHub Desktop.
/electric-moray/node_modules/moray/bin/batch
#!/usr/bin/env node
// -*- mode: js -*-
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*
* Copyright (c) 2017, Joyent, Inc.
*/
var assert = require('assert-plus');
var cmdutil = require('cmdutil');
var moray = require('../lib');
var moraycli = require('../lib/cmd');
var uuid = require('node-uuid');
var clientOptions, parser, client, requests;
var id = uuid.v4();
cmdutil.configure({
'usageMessage': 'update or delete batches of objects in Moray',
'synopses': [ moraycli.commonUsage + ' DATA' ]
});
clientOptions = {};
values = {};
parser = moraycli.parseCliOptions({
'argv': process.argv,
'env': process.env,
'errstream': process.stderr,
'extraOptStr': '',
'clientOptions': clientOptions,
'onUsage': cmdutil.usage
});
requests = JSON.parse(process.argv[2]);
assert.arrayOfObject(requests, 'requests');
client = moray.createClient(clientOptions);
client.on('error', cmdutil.fail);
client.on('connect', function onConnect() {
client.batch(requests, {req_id: id}, function callback(err) {
if (err) {
cmdutil.fail(err);
}
client.close();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment