Esempio n. 1
0
def reset_jobs_and_pipelines_statuses_to_idle():
    from controller.models import Pipeline, TaskEnqueued
    TaskEnqueued.query.delete()
    for pipeline in Pipeline.all():
        for job in pipeline.jobs:
            job.update(status='idle')
        pipeline.update(status='idle')
Esempio n. 2
0
 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
Esempio n. 3
0
 def _start_pipelines(self, pipeline_ids):
     """Tries finding and starting pipelines with IDs specified."""
     for pipeline_id in pipeline_ids:
         pipeline = Pipeline.find(pipeline_id)
         if pipeline is not None:
             pipeline.start()
             tracker = insight.GAProvider()
             tracker.track_event(category='pipelines', action='pubsub_run')
Esempio n. 4
0
 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
Esempio n. 5
0
 def _start_scheduled_pipelines(self):
     """Finds and tries starting the pipelines scheduled to be executed now."""
     for pipeline in Pipeline.where(run_on_schedule=True).all():
         for schedule in pipeline.schedules:
             if self._its_time(schedule.cron):
                 pipeline.start()
                 tracker = insight.GAProvider()
                 tracker.track_event(category='pipelines',
                                     action='scheduled_run')
                 break
Esempio n. 6
0
    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
Esempio n. 7
0
    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
Esempio n. 8
0
    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
Esempio n. 9
0
    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
Esempio n. 10
0
    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'
        }
Esempio n. 11
0
 def get(self, pipeline_id):
     pipeline = Pipeline.find(pipeline_id)
     abort_if_pipeline_doesnt_exist(pipeline, pipeline_id)
     return pipeline
Esempio n. 12
0
 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
Esempio n. 13
0
 def get(self):
     tracker = insight.GAProvider()
     tracker.track_event(category='pipelines', action='list')
     pipelines = Pipeline.all()
     return pipelines
Esempio n. 14
0
 def get(self):
     args = parser.parse_args()
     pipeline = Pipeline.find(args['pipeline_id'])
     jobs = pipeline.jobs.all()
     return jobs