def start_job(job_key): job_class = next((job for job in BackgroundJobManager.available_job_classes() if job.key() == job_key), None) if job_class: app.logger.info( f'Current user ({current_user.uid}) started job {job_class.key()}') job_class(app.app_context).run(force_run=True) return tolerant_jsonify(_job_class_to_json(job_class)) else: raise ResourceNotFoundError(f'Invalid job_key: {job_key}')
def job_schedule(): api_json = { 'autoStart': app.config['JOBS_AUTO_START'], 'jobs': [], 'secondsBetweenJobsCheck': app.config['JOBS_SECONDS_BETWEEN_PENDING_CHECK'], 'startedAt': to_isoformat(background_job_manager.get_started_at()), } for job in Job.get_all(include_disabled=True): job_class = next( (j for j in BackgroundJobManager.available_job_classes() if j.key() == job.key), None) if job_class: api_json['jobs'].append({ **job.to_api_json(), **_job_class_to_json(job_class), }) return tolerant_jsonify(api_json)