def post(self): args = parser.parse_args() pipeline = Pipeline(name=args['name']) pipeline.assign_attributes(args) pipeline.save() pipeline.save_relations(args) return pipeline, 201
def post(self): args = parser.parse_args() pipeline = Pipeline(name=args['name']) pipeline.assign_attributes(args) pipeline.save() pipeline.save_relations(args) tracker = insight.GAProvider() tracker.track_event(category='pipelines', action='create') return pipeline, 201
def patch(self, pipeline_id): pipeline = Pipeline.find(pipeline_id) args = parser.parse_args() schedule_pipeline = (args['run_on_schedule'] == 'True') pipeline.update(run_on_schedule=schedule_pipeline) tracker = insight.GAProvider() tracker.track_event( category='pipelines', action=('schedule' if schedule_pipeline else 'unschedule')) return pipeline
def delete(self, pipeline_id): pipeline = Pipeline.find(pipeline_id) abort_if_pipeline_doesnt_exist(pipeline, pipeline_id) if pipeline.is_blocked(): return { 'message': 'Removing of active pipeline is unavailable' }, 422 pipeline.destroy() return {}, 204
def get(self): """Finds and enqueues pipelines scheduled to be executed now.""" for pipeline in Pipeline.where(run_on_schedule=True).all(): logging.info('Checking schedules for pipeline %s', pipeline.name) for schedule in pipeline.schedules: logging.info('Checking schedule with cron string %s', schedule.cron) if self._its_time(schedule.cron): logging.info('Trying to start pipeline %s', pipeline.name) pipeline.start() break return 'OK', 200
def get(self): """Finds and enqueues pipelines scheduled to be executed now.""" for pipeline in Pipeline.where(run_on_schedule=True).all(): logging.info('Checking schedules for pipeline %s', pipeline.name) for schedule in pipeline.schedules: logging.info('Checking schedule with cron string %s', schedule.cron) if self._its_time(schedule.cron): logging.info('Trying to start pipeline %s', pipeline.name) pipeline.start() tracker = insight.GAProvider() tracker.track_event(category='pipelines', action='scheduled_run') break return 'OK', 200
def post(self): args = parser.parse_args() pipeline = Pipeline.find(args['pipeline_id']) if pipeline.is_blocked(): return { 'message': 'Creating new jobs for active pipeline is unavailable' }, 422 job = Job(args['name'], args['worker_class'], args['pipeline_id']) job.assign_attributes(args) job.save() job.save_relations(args) return job, 201
def put(self, pipeline_id): pipeline = Pipeline.find(pipeline_id) abort_if_pipeline_doesnt_exist(pipeline, pipeline_id) if pipeline.is_blocked(): return { 'message': 'Editing of active pipeline is unavailable' }, 422 args = parser.parse_args() pipeline.assign_attributes(args) pipeline.save() pipeline.save_relations(args) return pipeline, 200
def post(self): args = import_parser.parse_args() file_ = args['upload_file'] data = {} if file_: data = json.loads(file_.read()) pipeline = Pipeline(name=data['name']) pipeline.save() pipeline.import_data(data) return pipeline, 201 return data
def post(self): args = parser.parse_args() pipeline = Pipeline.find(args['pipeline_id']) if pipeline.is_blocked(): return { 'message': 'Creating new jobs for active pipeline is unavailable' }, 422 job = Job(args['name'], args['worker_class'], args['pipeline_id']) job.assign_attributes(args) job.save() job.save_relations(args) tracker = insight.GAProvider() tracker.track_event(category='jobs', action='create', label=args['worker_class']) return job, 201
def post(self): tracker = insight.GAProvider() tracker.track_event(category='pipelines', action='import') args = import_parser.parse_args() file_ = args['upload_file'] data = {} if file_: data = json.loads(file_.read()) pipeline = Pipeline(name=data['name']) pipeline.save() pipeline.import_data(data) return pipeline, 201 return data
def get(self, pipeline_id): tracker = insight.GAProvider() tracker.track_event(category='pipelines', action='export') pipeline = Pipeline.find(pipeline_id) jobs = self.__get_jobs__(pipeline) pipeline_params = [] for param in pipeline.params: pipeline_params.append({ 'name': param.name, 'value': param.value, 'type': param.type, }) pipeline_schedules = [] for schedule in pipeline.schedules: pipeline_schedules.append({ 'cron': schedule.cron, }) data = { 'name': pipeline.name, 'jobs': jobs, 'params': pipeline_params, 'schedules': pipeline_schedules } ts = time.time() pipeline_date = datetime.datetime.fromtimestamp(ts) pipeline_date_formatted = pipeline_date.strftime('%Y%m%d%H%M%S') filename = pipeline.name.lower( ) + "-" + pipeline_date_formatted + ".json" return data, 200, { 'Access-Control-Expose-Headers': 'Filename', 'Content-Disposition': "attachment; filename=" + filename, 'Filename': filename, 'Content-type': 'text/json' }
# Copyright 2018 Google Inc # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import run_ibackend from core.models import Pipeline # Reset status of pipelines and jobs to 'idle'. for p in Pipeline.all(): for j in p.jobs: j.update(status='idle') p.update(status='idle')
def get(self): pipelines = Pipeline.all() return pipelines
def get(self, pipeline_id): pipeline = Pipeline.find(pipeline_id) abort_if_pipeline_doesnt_exist(pipeline, pipeline_id) return pipeline
def post(self, pipeline_id): pipeline = Pipeline.find(pipeline_id) pipeline.stop() return pipeline
def reset_pipelines(): """Reset pipelines and jobs statuses.""" for pipeline in Pipeline.all(): for job in pipeline.jobs: job.update(status='idle') pipeline.update(status='idle')
def get(self): tracker = insight.GAProvider() tracker.track_event(category='pipelines', action='list') pipelines = Pipeline.all() return pipelines
def get(self): args = parser.parse_args() pipeline = Pipeline.find(args['pipeline_id']) jobs = pipeline.jobs.all() return jobs
def patch(self, pipeline_id): pipeline = Pipeline.find(pipeline_id) args = parser.parse_args() pipeline.update(run_on_schedule=(args['run_on_schedule'] == 'True')) return pipeline
def reset_jobs_and_pipelines_statuses_to_idle(): from core.models import Pipeline for pipeline in Pipeline.all(): for job in pipeline.jobs: job.update(status='idle') pipeline.update(status='idle')
def post(self, pipeline_id): pipeline = Pipeline.find(pipeline_id) pipeline.stop() tracker = insight.GAProvider() tracker.track_event(category='pipelines', action='manual_stop') return pipeline