MicroStrategy / mstrio-py

Python integration for MicroStrategy
Apache License 2.0
89 stars 57 forks source link

mstrio/distribution_services/schedule/schedule.py create schedule_type cannot be a str #181

Open hustontrevor opened 3 months ago

hustontrevor commented 3 months ago

Documentation shows class or str, but when 'time_based' is passed the create() fails inelegantly with "execution_details referenced before assignment"

Schedule.create(connection=self.mstr_conn,**schedule_def)

My failing schedule_def: {'description': 'Schedule for notification of file deliveries', 'schedule_type': 'time_based', 'start_date': '1/1/2004', 'recurrence_pattern': 'daily', 'daily_pattern': 'day', 'repeat_interval': 1, 'execution_pattern': 'repeat', 'execution_time': '00:00', 'start_time': '00:00', 'stop_time': '23:59', 'name': 'Xloop Daily 00:00 - 23:59 Every 1 Min'}

hustontrevor commented 3 months ago

execution_pattern also fails as a str

hustontrevor commented 3 months ago

Corrected body and needed adjustments:

{'description': 'Schedule for notification of file deliveries', 'schedule_type': 'time_based', 'start_date': '2004-01-01', 'recurrence_pattern': 'daily', 'daily_pattern': 'day', 'repeat_interval': '1', 'execution_pattern': 'repeat', 'execution_time': '00:00:00', 'start_time': '00:00:00', 'stop_time': '23:59:00', 'execution_repeat_interval': 1, 'name': 'Xloop Daily 00:00 - 23:59 Every 1 Min'}

def create_schedule(self,schedule_def):     
        schedule_def['schedule_type'] = Schedule.ScheduleType(schedule_def['schedule_type'])
        schedule_def['execution_pattern'] = ScheduleEnums.ExecutionPattern(schedule_def['execution_pattern'])
        schedule_def['recurrence_pattern'] = ScheduleEnums.RecurrencePattern(schedule_def['recurrence_pattern'])
        new_shed = Schedule.create(connection=self.mstr_conn,**schedule_def)
        return new_shed