{"size": 2279, "ext": "js", "max_stars_repo_path": "src/iexec-scheduler.js", "max_stars_repo_name": "ezaruba/iexec-sdk", "max_stars_repo_stars_event_min_datetime": "2021-04-04T20:37:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-04T20:37:58.000Z", "max_issues_repo_path": "src/iexec-scheduler.js", "max_issues_repo_name": "ezaruba/iexec-sdk", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/iexec-scheduler.js", "max_forks_repo_name": "ezaruba/iexec-sdk", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.1954022989, "max_line_length": 80, "alphanum_fraction": 0.5941202282}
#!/usr/bin/env node

const Debug = require('debug');
const cli = require('commander');
const {
  help,
  handleError,
  desc,
  option,
  Spinner,
  info,
  pretty,
} = require('./cli-helper');
const { loadAccountConf } = require('./fs');
const { loadChain } = require('./chains.js');

const debug = Debug('iexec:iexec-scheduler');
const objName = 'scheduler';

cli
  .command('show')
  .option(...option.chain())
  .option(...option.scheduler())
  .description(desc.showObj('version', objName))
  .action(async (cmd) => {
    const spinner = Spinner();
    try {
      const [{ iexec, scheduler }, { jwtoken }] = await Promise.all([
        loadChain(cmd.chain),
        loadAccountConf(),
      ]);

      iexec.server = cmd.scheduler || iexec.server;
      if (!iexec.server) {
        throw Error(
          'missing scheduler field in chain.json or scheduler cli argument',
        );
      }

      spinner.start(info.showing('version', objName));
      debug('scheduler', scheduler);
      const cookie = await iexec.getCookieByJWT(jwtoken);
      debug('cookie', cookie);
      const res = await iexec.get('version');
      const { version } = res.xwhep.Version[0].$;

      const details = {
        version,
      };
      spinner.succeed(`scheduler ${scheduler} details:${pretty(details)}`);
    } catch (error) {
      handleError(error, cli);
    }
  });

cli
  .command('api')
  .option(...option.chain())
  .description('direct call of scheduler API methods')
  .action(async (cmd) => {
    const spinner = Spinner();
    try {
      const [{ iexec, scheduler }, { jwtoken }] = await Promise.all([
        loadChain(cmd.chain),
        loadAccountConf(),
      ]);

      const fnName = cli.args[0];
      const fnArgs = cli.args.slice(1, cli.args.length - 1);
      debug('fnName', fnName);
      debug('fnArgs', fnArgs);
      const methodName = fnName.concat('(', fnArgs.join(', '), ')');
      spinner.start(`calling ${methodName} on iExec scheduler ${scheduler}...`);

      const cookie = await iexec.getCookieByJWT(jwtoken);
      debug('cookie', cookie);

      const res = await iexec[fnName](...fnArgs);

      spinner.succeed(`scheduler ${scheduler} details:${pretty(res)}`);
    } catch (error) {
      handleError(error, cli);
    }
  });

help(cli);
