示例#1
0
 def test_remove_schedules_many_schedules_random_schedules(self):
     # Number of jobs and floor(requests) + ceiling(requests) are equal
     num_of_jobs = MANY
     num_of_schedules = num_of_jobs
     # Leave one schedule remaining for comparison at the end
     num_of_requests = num_of_jobs - 1
     # Create a crontab with many jobs
     test_jobs = create_test_tab(num_of_jobs, user1)
     api.set_jobs(test_jobs, user1)
     jobs_list = api.get_jobs()
     test_workers = []
     # Create one worker and add them to a list for bookkeeping
     test_workers.append(api.create_worker())
     test_schedules = []
     for schedule in range(num_of_schedules):
         test_schedules.append(api.Schedule(datetime.now(),
                               test_jobs[schedule], test_workers[0]))
     api.add_schedules(test_schedules)
     # Kill number of requests random schedules in the list
     for request in range(num_of_requests):
         random_schedule = random.randrange(len(test_schedules))
         api.remove_schedule(test_schedules.pop(random_schedule))
     schedules_list = []
     schedules_list = api.get_schedules(test_workers[0])
     # Verify that the schedules list contains exactly one schedule
     self.assertEqual(len(schedules_list), 1)
     # Verify that the correct remaining schedule is still in the list
     check_schedule_fields(self, schedules_list, test_schedules)
示例#2
0
 def test_remove_schedules_many_schedules_random_schedules(self):
     # Number of jobs and floor(requests) + ceiling(requests) are equal
     num_of_jobs = MANY
     num_of_schedules = num_of_jobs
     # Leave one schedule remaining for comparison at the end
     num_of_requests = num_of_jobs - 1
     # Create a crontab with many jobs
     test_jobs = create_test_tab(num_of_jobs, user1)
     api.set_jobs(test_jobs, user1)
     jobs_list = api.get_jobs()
     test_workers = []
     # Create one worker and add them to a list for bookkeeping
     test_workers.append(api.create_worker())
     test_schedules = []
     for schedule in range(num_of_schedules):
         test_schedules.append(
             api.Schedule(datetime.now(), test_jobs[schedule],
                          test_workers[0]))
     api.add_schedules(test_schedules)
     # Kill number of requests random schedules in the list
     for request in range(num_of_requests):
         random_schedule = random.randrange(len(test_schedules))
         api.remove_schedule(test_schedules.pop(random_schedule))
     schedules_list = []
     schedules_list = api.get_schedules(test_workers[0])
     # Verify that the schedules list contains exactly one schedule
     self.assertEqual(len(schedules_list), 1)
     # Verify that the correct remaining schedule is still in the list
     check_schedule_fields(self, schedules_list, test_schedules)
示例#3
0
 def test_remove_schedule_many_schedules(self):
     # Number of jobs and floor(requests) + ceiling(requests) are equal
     num_of_jobs = MANY
     num_of_schedules = num_of_jobs
     # Automatic flooring care of Python
     num_of_requests = num_of_jobs / 2
     # Create a crontab with many jobs
     test_jobs = create_test_tab(num_of_jobs, user1)
     api.set_jobs(test_jobs, user1)
     jobs_list = api.get_jobs()
     test_workers = []
     # Create one worker and add them to a list for bookkeeping
     test_workers.append(api.create_worker())
     # Create a schedule for many jobs
     test_schedules = []
     for schedule in range(num_of_schedules):
         test_schedules.append(api.Schedule(datetime.now(),
                               test_jobs[schedule], test_workers[0]))
     api.add_schedules(test_schedules)
     # Kill the floor of half of the workers in the list
     for request in range(num_of_requests):
         api.remove_schedule(test_schedules.pop())
     schedules_list = api.get_schedules(test_workers[0])
     # Verify that the correct remaining schedules are still in the list
     check_schedule_fields(self, schedules_list, test_schedules)
     # Remove all remaining test schedules
     while test_schedules:
         api.remove_schedule(test_schedules.pop())
     # Try to get schedules from an empty pool
     schedules_list = api.get_schedules(test_workers[0])
     # Verify that the next worker does not exist
     self.assertFalse(len(schedules_list))
示例#4
0
 def test_remove_schedule_many_schedules(self):
     # Number of jobs and floor(requests) + ceiling(requests) are equal
     num_of_jobs = MANY
     num_of_schedules = num_of_jobs
     # Automatic flooring care of Python
     num_of_requests = num_of_jobs / 2
     # Create a crontab with many jobs
     test_jobs = create_test_tab(num_of_jobs, user1)
     api.set_jobs(test_jobs, user1)
     jobs_list = api.get_jobs()
     test_workers = []
     # Create one worker and add them to a list for bookkeeping
     test_workers.append(api.create_worker())
     # Create a schedule for many jobs
     test_schedules = []
     for schedule in range(num_of_schedules):
         test_schedules.append(
             api.Schedule(datetime.now(), test_jobs[schedule],
                          test_workers[0]))
     api.add_schedules(test_schedules)
     # Kill the floor of half of the workers in the list
     for request in range(num_of_requests):
         api.remove_schedule(test_schedules.pop())
     schedules_list = api.get_schedules(test_workers[0])
     # Verify that the correct remaining schedules are still in the list
     check_schedule_fields(self, schedules_list, test_schedules)
     # Remove all remaining test schedules
     while test_schedules:
         api.remove_schedule(test_schedules.pop())
     # Try to get schedules from an empty pool
     schedules_list = api.get_schedules(test_workers[0])
     # Verify that the next worker does not exist
     self.assertFalse(len(schedules_list))
示例#5
0
def _run_schedules(events):
    global _schedules
    global _run_schedules_event

    if len(_schedules) > 0:
        schedule = _schedules[-1]
        time_to_run = schedule.time_to_run
        seconds_to_next_run = (time_to_run - datetime.now()).total_seconds()
        if seconds_to_next_run <= 0:
            _run_command(schedule.job.command, schedule.job.user_id)
            api.remove_schedule(schedule)
            _schedules.pop()

            _run_schedules_event = events.enter(seconds_to_next_run, 1,
                                                _run_schedules, (events,))

    _run_schedules_event = None
示例#6
0
def _run_schedules(events):
    global _schedules
    global _run_schedules_event

    if len(_schedules) > 0:
        schedule = _schedules[-1]
        time_to_run = schedule.time_to_run
        seconds_to_next_run = (time_to_run - datetime.now()).total_seconds()
        if seconds_to_next_run <= 0:
            _run_command(schedule.job.command, schedule.job.user_id,
                         schedule.job.environment, schedule.job.job_input)
            api.remove_schedule(schedule)
            _schedules.pop()

            _run_schedules_event = events.enter(seconds_to_next_run, 1,
                                                _run_schedules, (events, ))

    _run_schedules_event = None
示例#7
0
 def test_remove_schedule_one_schedule(self):
     num_of_jobs = ONE
     num_of_schedules = num_of_jobs
     # Create a crontab with one job
     test_jobs = create_test_tab(num_of_jobs, user1)
     api.set_jobs(test_jobs, user1)
     jobs_list = api.get_jobs()
     test_workers = []
     # Create one worker and add them to a list for bookkeeping
     test_workers.append(api.create_worker())
     # Create a schedule for the only job
     test_schedules = []
     test_schedules.append(api.Schedule(datetime.now(), test_jobs[0],
                           test_workers[0]))
     api.add_schedules(test_schedules)
     # Kill the only schedule in the list
     api.remove_schedule(test_schedules[0])
     schedules_list = api.get_schedules(test_workers[0])
     # Verify that the schedules list is empty
     self.assertFalse(len(schedules_list))
示例#8
0
 def test_remove_schedule_one_schedule(self):
     num_of_jobs = ONE
     num_of_schedules = num_of_jobs
     # Create a crontab with one job
     test_jobs = create_test_tab(num_of_jobs, user1)
     api.set_jobs(test_jobs, user1)
     jobs_list = api.get_jobs()
     test_workers = []
     # Create one worker and add them to a list for bookkeeping
     test_workers.append(api.create_worker())
     # Create a schedule for the only job
     test_schedules = []
     test_schedules.append(
         api.Schedule(datetime.now(), test_jobs[0], test_workers[0]))
     api.add_schedules(test_schedules)
     # Kill the only schedule in the list
     api.remove_schedule(test_schedules[0])
     schedules_list = api.get_schedules(test_workers[0])
     # Verify that the schedules list is empty
     self.assertFalse(len(schedules_list))