Exemplo n.º 1
0
def get_num_schedules():
    sum = 0
    for worker in api.get_workers():
        sum += len(api.get_schedules(worker))
    if sum == 1:
        print("There is 1 schedule")
    else:
        print("There are %d schedules" % sum)
Exemplo n.º 2
0
def get_num_schedules():
    sum = 0
    for worker in api.get_workers():
        sum += len(api.get_schedules(worker))
    if sum == 1:
        print("There is 1 schedule")
    else:
        print("There are %d schedules" % sum)
Exemplo n.º 3
0
def check_worker_heartbeat(events):
    for w in api.get_workers():
        if (datetime.now() - w.heartbeat) > WORKER_HEARTBEAT_TIMEOUT:
            for schedule in api.get_schedules(w):
                schedule.worker = api.get_next_worker()

            api.destroy_worker(w)

    delay = WORKER_HEARTBEAT_TIMEOUT.total_seconds()
    events.enter(delay, 1, check_worker_heartbeat, (events, ))
Exemplo n.º 4
0
 def test_get_workers_one_worker(self):
     num_of_workers = ONE
     test_workers = []
     # Create one worker and add them to a list for bookkeeping
     test_workers.append(api.create_worker())
     workers_list = api.get_workers()
     # Verify that the workers list contains exactly one worker
     self.assertEqual(len(workers_list), num_of_workers)
     # Verify that the information we get is the same as what was set
     check_worker_fields(self, workers_list, test_workers)
Exemplo n.º 5
0
 def test_get_workers_one_worker(self):
     num_of_workers = ONE
     test_workers = []
     # Create one worker and add them to a list for bookkeeping
     test_workers.append(api.create_worker())
     workers_list = api.get_workers()
     # Verify that the workers list contains exactly one worker
     self.assertEqual(len(workers_list), num_of_workers)
     # Verify that the information we get is the same as what was set
     check_worker_fields(self, workers_list, test_workers)
Exemplo n.º 6
0
 def test_get_workers_many_workers(self):
     num_of_workers = MANY
     test_workers = []
     for job in range(num_of_workers):
         # Create workers and add them to a list for bookkeeping
         test_workers.append(api.create_worker())
     workers_list = api.get_workers()
     # Verify that the workers list contains the correct number of workers
     self.assertEqual(len(workers_list), num_of_workers)
     check_worker_fields(self, workers_list, test_workers)
Exemplo n.º 7
0
 def test_get_workers_many_workers(self):
     num_of_workers = MANY
     test_workers = []
     for job in range(num_of_workers):
         # Create workers and add them to a list for bookkeeping
         test_workers.append(api.create_worker())
     workers_list = api.get_workers()
     # Verify that the workers list contains the correct number of workers
     self.assertEqual(len(workers_list), num_of_workers)
     check_worker_fields(self, workers_list, test_workers)
Exemplo n.º 8
0
def check_worker_heartbeat(events):
    for w in api.get_workers():
        if (datetime.now() - w.heartbeat) > WORKER_HEARTBEAT_TIMEOUT:
            for schedule in api.get_schedules(w):
                schedule.worker = api.get_next_worker()

            api.destroy_worker(w)

    delay = WORKER_HEARTBEAT_TIMEOUT.total_seconds()
    events.enter(delay, 1, check_worker_heartbeat, (events,))
Exemplo n.º 9
0
def check_scheduler(events):
    for w in api.get_workers():
        if (datetime.now() - w.heartbeat) <= WORKER_HEARTBEAT_TIMEOUT:
            if w == worker.worker:
                create_schedules(events)
                check_worker_heartbeat(events)
            else:
                delay = WORKER_HEARTBEAT_TIMEOUT.total_seconds()
                events.enter(delay, 1, check_scheduler, (events, ))

            return
Exemplo n.º 10
0
def check_scheduler(events):
    for w in api.get_workers():
        if (datetime.now() - w.heartbeat) <= WORKER_HEARTBEAT_TIMEOUT:
            if w == worker.worker:
                create_schedules(events)
                check_worker_heartbeat(events)
            else:
                delay = WORKER_HEARTBEAT_TIMEOUT.total_seconds()
                events.enter(delay, 1, check_scheduler, (events,))

            return
Exemplo n.º 11
0
def get_next_schedule_time():
    now = datetime.now()
    comp = datetime.max
    for worker in api.get_workers():
        for schedule in api.get_schedules(worker):
            if comp > schedule.time_to_run > now:
                comp = schedule.time_to_run
    if comp != datetime.max:
        print("The next job will run at " + comp.strftime("%d %B %Y %I:%M%p"))
    else:
        print("No scheduled jobs to run")
Exemplo n.º 12
0
def get_next_schedule_time():
    now = datetime.now()
    comp = datetime.max
    for worker in api.get_workers():
        for schedule in api.get_schedules(worker):
            if comp > schedule.time_to_run > now:
                comp = schedule.time_to_run
    if comp != datetime.max:
        print("The next job will run at " + comp.strftime("%d %B %Y %I:%M%p"))
    else:
        print("No scheduled jobs to run")
Exemplo n.º 13
0
 def test_update_heartbeat_one_worker(self):
     test_workers = []
     # Create one worker and it to a list for bookkeeping
     test_workers.append(api.create_worker())
     # Get the original heartbeat of the only worker
     previous_heartbeats = []
     previous_heartbeats.append(test_workers[0].heartbeat)
     # Old heartbeat is before checkpoint, new heartbeat should be after
     checkpoint1 = datetime.now()
     api.update_heartbeat(test_workers[0])
     workers_list = []
     workers_list = api.get_workers()
     checkpoint2 = datetime.now()
     # Verify that the heartbeat has been updated correctly and previous
     # heartbeat was not an unexpected value
     check_heartbeat_value(self, workers_list[0], previous_heartbeats,
                           checkpoint1, checkpoint2, 0)
Exemplo n.º 14
0
 def test_update_heartbeat_one_worker(self):
     test_workers = []
     # Create one worker and it to a list for bookkeeping
     test_workers.append(api.create_worker())
     # Get the original heartbeat of the only worker
     previous_heartbeats = []
     previous_heartbeats.append(test_workers[0].heartbeat)
     # Old heartbeat is before checkpoint, new heartbeat should be after
     checkpoint1 = datetime.now()
     api.update_heartbeat(test_workers[0])
     workers_list = []
     workers_list = api.get_workers()
     checkpoint2 = datetime.now()
     # Verify that the heartbeat has been updated correctly and previous
     # heartbeat was not an unexpected value
     check_heartbeat_value(self, workers_list[0], previous_heartbeats,
                           checkpoint1, checkpoint2, 0)
Exemplo n.º 15
0
 def test_update_heartbeat_one_worker_many_requests(self):
     num_of_requests = MANY
     test_workers = []
     # Create many workers and them to a list for bookkeeping
     test_workers.append(api.create_worker())
     # Get the original heartbeat of the only worker
     previous_heartbeats = []
     previous_heartbeats.append(test_workers[0].heartbeat)
     checkpoint1 = datetime.now()
     workers_list = []
     for request in range(num_of_requests):
         api.update_heartbeat(test_workers[0])
         workers_list = api.get_workers()
         checkpoint2 = datetime.now()
         # Verify that the heartbeat has been updated correctly and previous
         # heartbeat was not an unexpected value
         check_heartbeat_value(self, workers_list[0], previous_heartbeats,
                               checkpoint1, checkpoint2, 0)
Exemplo n.º 16
0
 def test_update_heartbeat_one_worker_many_requests(self):
     num_of_requests = MANY
     test_workers = []
     # Create many workers and them to a list for bookkeeping
     test_workers.append(api.create_worker())
     # Get the original heartbeat of the only worker
     previous_heartbeats = []
     previous_heartbeats.append(test_workers[0].heartbeat)
     checkpoint1 = datetime.now()
     workers_list = []
     for request in range(num_of_requests):
         api.update_heartbeat(test_workers[0])
         workers_list = api.get_workers()
         checkpoint2 = datetime.now()
         # Verify that the heartbeat has been updated correctly and previous
         # heartbeat was not an unexpected value
         check_heartbeat_value(self, workers_list[0], previous_heartbeats,
                               checkpoint1, checkpoint2, 0)
Exemplo n.º 17
0
 def test_destroy_worker_many_workers_random_workers(self):
     # Number of workers and floor(requests) + ceiling(requests) are equal
     num_of_workers = MANY
     # Leave one worker remaining for comparison at the end
     num_of_requests = num_of_workers - 1
     # Automatic flooring care of Python
     test_workers = []
     for worker in range(num_of_workers):
         # Create many workers and add them to a list for bookkeeping
         test_workers.append(api.create_worker())
     # Kill number of requests random worker in the list
     for request in range(num_of_requests):
         random_worker = random.randrange(len(test_workers))
         api.destroy_worker(test_workers.pop(random_worker))
     workers_list = []
     workers_list = api.get_workers()
     # Verify that the workers list contains exactly one worker
     self.assertEqual(len(workers_list), 1)
     # Verify that the correct remaining worker is still in the list
     check_worker_fields(self, workers_list, test_workers)
Exemplo n.º 18
0
 def test_destroy_worker_many_workers_random_workers(self):
     # Number of workers and floor(requests) + ceiling(requests) are equal
     num_of_workers = MANY
     # Leave one worker remaining for comparison at the end
     num_of_requests = num_of_workers - 1
     # Automatic flooring care of Python
     test_workers = []
     for worker in range(num_of_workers):
         # Create many workers and add them to a list for bookkeeping
         test_workers.append(api.create_worker())
     # Kill number of requests random worker in the list
     for request in range(num_of_requests):
         random_worker = random.randrange(len(test_workers))
         api.destroy_worker(test_workers.pop(random_worker))
     workers_list = []
     workers_list = api.get_workers()
     # Verify that the workers list contains exactly one worker
     self.assertEqual(len(workers_list), 1)
     # Verify that the correct remaining worker is still in the list
     check_worker_fields(self, workers_list, test_workers)
Exemplo n.º 19
0
 def test_update_heartbeat_many_workers_random_worker(self):
     # Number of workers and floor(requests) + ceiling(requests) are equal 
     num_of_workers = MANY
     test_workers = []
     previous_heartbeats = []
     # Create many workers and them to a list for bookkeeping
     for worker in range(num_of_workers):
         test_workers.append(api.create_worker())
     # Get the original heartbeat of each worker
     checkpoint1 = datetime.now()
     for worker in test_workers:
         previous_heartbeats.append(worker.heartbeat)
         random_worker = random.randrange(num_of_workers)
     api.update_heartbeat(test_workers[random_worker])
     workers_list = []
     workers_list = api.get_workers()
     checkpoint2 = datetime.now()
     # Verify that the random worker's heartbeat has been updated correctly
     # and its previous heartbeat was not an unexpected value
     check_heartbeat_value(self, workers_list[random_worker], 
     previous_heartbeats, checkpoint1, checkpoint2, random_worker)
Exemplo n.º 20
0
 def test_update_heartbeat_many_workers_random_worker(self):
     # Number of workers and floor(requests) + ceiling(requests) are equal
     num_of_workers = MANY
     test_workers = []
     previous_heartbeats = []
     # Create many workers and them to a list for bookkeeping
     for worker in range(num_of_workers):
         test_workers.append(api.create_worker())
     # Get the original heartbeat of each worker
     checkpoint1 = datetime.now()
     for worker in test_workers:
         previous_heartbeats.append(worker.heartbeat)
         random_worker = random.randrange(num_of_workers)
     api.update_heartbeat(test_workers[random_worker])
     workers_list = []
     workers_list = api.get_workers()
     checkpoint2 = datetime.now()
     # Verify that the random worker's heartbeat has been updated correctly
     # and its previous heartbeat was not an unexpected value
     check_heartbeat_value(self, workers_list[random_worker],
                           previous_heartbeats, checkpoint1, checkpoint2,
                           random_worker)
Exemplo n.º 21
0
 def test_update_heartbeat_many_workers_many_requests(self):
     num_of_workers = MANY
     test_workers = []
     previous_heartbeats = []
     # Create many workers and them to a list for bookkeeping
     for worker in range(num_of_workers):
         test_workers.append(api.create_worker())
     # Get the original heartbeat of each worker
     for worker in test_workers:
         previous_heartbeats.append(worker.heartbeat)
     checkpoint1 = datetime.now()
     for worker in test_workers:
         api.update_heartbeat(worker)
     workers_list = []
     workers_list = api.get_workers()
     checkpoint2 = datetime.now()
     # Verify that the heartbeats have been updated correctly and previous
     # heartbeats were not an unexpected value
     current = 0
     for worker in workers_list:
         check_heartbeat_value(self, worker, previous_heartbeats,
                               checkpoint1, checkpoint2, current)
         current += 1
Exemplo n.º 22
0
 def test_destroy_worker_many_workers(self):
     # Number of workers and floor(requests) + ceiling(requests) are equal
     num_of_workers = MANY
     # Automatic flooring care of Python
     num_of_requests = num_of_workers/2
     test_workers = []
     for worker in range(num_of_workers):
         # Create many workers and add them to a list for bookkeeping
         test_workers.append(api.create_worker())
     # Kill the floor of half of the workers in the list
     for request in range(num_of_requests):
         api.destroy_worker(test_workers.pop())
     workers_list = []
     workers_list = api.get_workers()
     # Verify that the correct workers are still in the list
     check_worker_fields(self, workers_list, test_workers)
     # Remove the rest of the test workers
     while test_workers:
         api.destroy_worker(test_workers.pop())
     # Try to get a worker from an empty pool
     next_worker = api.get_next_worker()
     # Verify that the next worker does not exist
     self.assertEqual(next_worker, None)
Exemplo n.º 23
0
 def test_destroy_worker_many_workers(self):
     # Number of workers and floor(requests) + ceiling(requests) are equal
     num_of_workers = MANY
     # Automatic flooring care of Python
     num_of_requests = num_of_workers / 2
     test_workers = []
     for worker in range(num_of_workers):
         # Create many workers and add them to a list for bookkeeping
         test_workers.append(api.create_worker())
     # Kill the floor of half of the workers in the list
     for request in range(num_of_requests):
         api.destroy_worker(test_workers.pop())
     workers_list = []
     workers_list = api.get_workers()
     # Verify that the correct workers are still in the list
     check_worker_fields(self, workers_list, test_workers)
     # Remove the rest of the test workers
     while test_workers:
         api.destroy_worker(test_workers.pop())
     # Try to get a worker from an empty pool
     next_worker = api.get_next_worker()
     # Verify that the next worker does not exist
     self.assertEqual(next_worker, None)
Exemplo n.º 24
0
 def test_update_heartbeat_many_workers_many_requests(self):
     num_of_workers = MANY
     test_workers = []
     previous_heartbeats = []
     # Create many workers and them to a list for bookkeeping
     for worker in range(num_of_workers):
         test_workers.append(api.create_worker())
     # Get the original heartbeat of each worker
     for worker in test_workers:
         previous_heartbeats.append(worker.heartbeat)
     checkpoint1 = datetime.now()
     for worker in test_workers:
         api.update_heartbeat(worker)
     workers_list = []
     workers_list = api.get_workers()
     checkpoint2 = datetime.now()
     # Verify that the heartbeats have been updated correctly and previous
     # heartbeats were not an unexpected value
     current = 0
     for worker in workers_list:
         check_heartbeat_value(self, worker, previous_heartbeats,
                               checkpoint1, checkpoint2, current)
         current += 1
Exemplo n.º 25
0
def get_worker_status():
    L = len(api.get_workers())
    if L == 1:
        print("1 worker is up")
    else:
        print("%d workers are up" % L)
Exemplo n.º 26
0
def get_worker_status():
    L = len(api.get_workers())
    if L == 1:
        print("1 worker is up")
    else:
        print("%d workers are up" % L)
Exemplo n.º 27
0
 def test_get_workers_empty_workers(self):
     num_of_workers = ZERO
     workers_list = api.get_workers()
     # Verify that workers list is empty
     self.assertFalse(len(workers_list))
Exemplo n.º 28
0
 def test_get_workers_empty_workers(self):
     num_of_workers = ZERO
     workers_list = api.get_workers()
     # Verify that workers list is empty
     self.assertFalse(len(workers_list))