def execute(self, context): try: config = context.get_job_config(context.options.jobspec, context.options.config_file) except Config.InvalidConfigError as e: raise context.CommandError(EXIT_INVALID_CONFIGURATION, 'Error loading job configuration: %s' % e) api = context.get_api(config.cluster()) monitor = JobMonitor(api, config.role(), config.environment(), config.name()) resp = api.create_job(config) context.check_and_log_response(resp) if context.options.open_browser: context.open_job_page(api, config) if context.options.wait_until == 'RUNNING': monitor.wait_until(monitor.running_or_finished) elif context.options.wait_until == 'FINISHED': monitor.wait_until(monitor.terminal)
def create(job_spec, config_file): """usage: create cluster/role/env/job config Creates a job based on a configuration file. """ options = app.get_options() try: config = get_job_config(job_spec, config_file, options) except ValueError as v: print("Error: %s" % v) sys.exit(1) api = make_client(config.cluster()) monitor = JobMonitor(api, config.role(), config.environment(), config.name()) resp = api.create_job(config) check_and_log_response(resp) handle_open(api.scheduler.scheduler().url, config.role(), config.environment(), config.name()) if options.wait_until == 'RUNNING': monitor.wait_until(monitor.running_or_finished) elif options.wait_until == 'FINISHED': monitor.wait_until(monitor.terminal)
def test_init(self): result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=[])) response = Response(responseCode=ResponseCode.OK, message="test", result=result) query = TaskQuery(owner=Identity(role=ROLE), environment=ENV, jobName=JOB_NAME) self.mock_scheduler.getTasksStatus(query).AndReturn(response) self.mox.ReplayAll() JobMonitor(self.mock_api, ROLE, ENV, JOB_NAME)