Esempio n. 1
0
    def _schedule_row_to_schedule(cls, schedule_id: uuid.UUID,
                                  schedule_row: _ScheduleRow) -> Schedule:
        schedule_type = schedule_row.type

        if schedule_type == Schedule.Type.STARTUP:
            schedule = StartUpSchedule()
        elif schedule_type == Schedule.Type.TIMED:
            schedule = TimedSchedule()
        elif schedule_type == Schedule.Type.INTERVAL:
            schedule = IntervalSchedule()
        elif schedule_type == Schedule.Type.MANUAL:
            schedule = ManualSchedule()
        else:
            raise ValueError("Unknown schedule type {}", schedule_type)

        schedule.schedule_id = schedule_id
        schedule.exclusive = schedule_row.exclusive
        schedule.name = schedule_row.name
        schedule.process_name = schedule_row.process_name
        schedule.repeat = schedule_row.repeat

        if schedule_type == Schedule.Type.TIMED:
            schedule.day = schedule_row.day
            schedule.time = schedule_row.time
        else:
            schedule.day = None
            schedule.time = None

        return schedule
Esempio n. 2
0
 async def mock_schedule(_type):
     if _type == 1:
         schedule = StartUpSchedule()
         schedule.repeat = None
         schedule.time = None
         schedule.day = None
     elif _type == 2:
         schedule = TimedSchedule()
         schedule.repeat = None
         schedule.time = datetime(1, 1, 1, 0, 0, 10)
         schedule.day = 1
     elif _type == 3:
         schedule = IntervalSchedule()
         schedule.repeat = timedelta(seconds=15)
         schedule.time = None
         schedule.day = None
     else:
         schedule = ManualSchedule()
         schedule.repeat = None
         schedule.time = None
         schedule.day = None
     schedule.schedule_id = self._random_uuid
     schedule.exclusive = True
     schedule.enabled = True
     schedule.name = "foo"
     schedule.process_name = "bar"
     return schedule
Esempio n. 3
0
 async def mock_coro():
     schedule = StartUpSchedule()
     schedule.schedule_id = self._random_uuid
     schedule.exclusive = True
     schedule.enabled = True
     schedule.name = "foo"
     schedule.process_name = "bar"
     schedule.repeat = timedelta(seconds=30)
     schedule.time = None
     schedule.day = None
     return schedule
Esempio n. 4
0
 async def mock_coro():
     schedules = []
     schedule = StartUpSchedule()
     schedule.schedule_id = "1"
     schedule.exclusive = True
     schedule.enabled = True
     schedule.name = "foo"
     schedule.process_name = "bar"
     schedule.repeat = timedelta(seconds=30)
     schedule.time = None
     schedule.day = None
     schedules.append(schedule)
     return schedules
Esempio n. 5
0
 async def mock_schedule(*args):
     schedule = StartUpSchedule()
     schedule.schedule_id = self._random_uuid
     schedule.exclusive = True
     schedule.enabled = True
     schedule.process_name = "bar"
     schedule.repeat = timedelta(seconds=30)
     schedule.time = None
     schedule.day = None
     if args[0] == 1:
         schedule.name = "foo"
     else:
         schedule.name = "new"
     return schedule
Esempio n. 6
0
async def _execute_add_update_schedule(data, curr_value=None):
    """
    Private method common to create a new schedule and update an existing schedule

    Args:
         data:

    Returns:
            schedule_id (new for created, existing for updated)
    """

    _schedule = _extract_args(data, curr_value)

    # Create schedule object as Scheduler.save_schedule requires an object
    if _schedule.get('schedule_type') == Schedule.Type.STARTUP:
        schedule = StartUpSchedule()
    elif _schedule.get('schedule_type') == Schedule.Type.TIMED:
        schedule = TimedSchedule()
        schedule.day = _schedule.get('schedule_day')
        m, s = divmod(_schedule.get('schedule_time'), 60)
        h, m = divmod(m, 60)
        schedule.time = datetime.time().replace(hour=h, minute=m, second=s)
    elif _schedule.get('schedule_type') == Schedule.Type.INTERVAL:
        schedule = IntervalSchedule()
    elif _schedule.get('schedule_type') == Schedule.Type.MANUAL:
        schedule = ManualSchedule()

    # Populate scheduler object
    schedule.schedule_id = _schedule.get('schedule_id')
    schedule.name = _schedule.get('schedule_name')
    schedule.process_name = _schedule.get('schedule_process_name')
    schedule.repeat = datetime.timedelta(seconds=_schedule['schedule_repeat'])

    schedule.exclusive = True if _schedule.get(
        'schedule_exclusive') == 'True' else False
    schedule.enabled = True if _schedule.get(
        'schedule_enabled') == 'True' else False

    # Save schedule
    await server.Server.scheduler.save_schedule(
        schedule, _schedule['is_enabled_modified'])

    updated_schedule_id = schedule.schedule_id

    return updated_schedule_id