def stop_cronjob(id): try: session = Session() cronjob = session.query(CronJob).filter(CronJob.id == id).first() if cronjob.status != 'Stopped': cronjob_service.disable_cron_job(id) cronjob_repository.edit_cronjob(session, cronjob, 'Stopped') session.close() return jsonify(response='error', msg='Cronjob {0} was disabled'.format(id)) else: return jsonify(response='error', msg='Cronjob {0} is already disabled'.format(id)) except AttributeError as e: return jsonify(response='error', msg='Cronjob {0} was not found, {1}'.format(id, str(e))) except Exception as e: return jsonify(response='error', msg='An error occurred while disabling cronjob {0}, {1}'.format(id, str(e)))
def activate_cronjob(id): try: session = Session() cronjob = session.query(CronJob).filter(CronJob.id == id).first() print(cronjob.status) if cronjob.status == 'Stopped': cronjob_service.enable_cron_job(id) cronjob_repository.edit_cronjob(session, cronjob, 'Enabled') session.close() return jsonify(response='success', msg='Cronjob {0} was activated'.format(id)) else: return jsonify(response='error', msg='Cronjob {0} is already running'.format(id)) except AttributeError as e: return jsonify(response='error', msg='Cronjob {0} was not found'.format(id)) except Exception as e: return jsonify(response='error', msg='An error occurred while activating cronjob {0}'.format(id, str(e)))
from src.repositories.entity import Session from src.entities.user import User from src.entities.role import Role from src.repositories.role_repository import fetch_role from datetime import datetime from src.repositories.entity import init_db init_db() session = Session() try: role = session.query(Role).filter(Role.name == 'Admin').first() if not role: role = Role('Admin', 'This is the admin role') session.add(role) session.commit() user = session.query(User).filter( User.email == '*****@*****.**').first() if not user: role = fetch_role(session, 'Admin') cDate = datetime.now() user = User('test', '*****@*****.**', '123456', cDate, role) session.add(user) session.commit() session.close() except Exception as e: print(str(e))