コード例 #1
0
def add_device():
    session = Session()
    new_device = Device("9422", "172.65.112.13", "3")
    session.add(new_device)
    session.commit()
    session.close()
    click.echo('device added')
コード例 #2
0
def generate_cron_job():
    session = Session()
    cronjob_from_request = request.get_json()
    print("cronjob_from_request: ", cronjob_from_request)
    # try:
    # The cronjob is only added and is not committed until it runs
    # successfully; in case of an error: session.rollback()
    cron_job, message, response = cronjob_repository.generate_cron_job(
        session, cronjob_from_request, 'Pending', datetime.datetime.now())
    if (response):
        status = cronjob_service.add_cron_job(cronjob_from_request, cron_job)
        session.commit()
        session.close()
    else:
        status = "Error"
        session.rollback()
        message = 'schedule failed'

    return jsonify(cronjob_from_request, status, response, message), 201
コード例 #3
0
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))