Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: python
services:
- redis-server
before_script:
- pip install pyflakes
script:
- python -m unittest tests/test*
99 changes: 47 additions & 52 deletions jobManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,61 +63,56 @@ def _getNextID(self):
def __manage(self):
self.running = True
while True:
id = self.jobQueue.getNextPendingJob()

if id:
job = self.jobQueue.get(id)

# job could no longer exist if it was completed by someone else
if job == None:
continue

if not job.accessKey and Config.REUSE_VMS:
id, vm = self.jobQueue.getNextPendingJobReuse(id)
job = self.jobQueue.get(id)
if job == None:
continue

try:
# Mark the job assigned
self.jobQueue.assignJob(job.id)
# if the job has specified an account
# create an VM on the account and run on that instance
if job.accessKeyId:
from vmms.ec2SSH import Ec2SSH
vmms = Ec2SSH(job.accessKeyId, job.accessKey)
newVM = copy.deepcopy(job.vm)
newVM.id = self._getNextID()
preVM = vmms.initializeVM(newVM)
# Blocks until we get a next job
job = self.jobQueue.getNextPendingJob()

if not job.accessKey and Config.REUSE_VMS:
vm = None
while vm is None:
vm = self.jobQueue.reuseVM(job)
# Sleep for a bit and then check again
time.sleep(Config.DISPATCH_PERIOD)

try:
# Mark the job assigned
job.makeAssigned()
# if the job has specified an account
# create an VM on the account and run on that instance
if job.accessKeyId:
from vmms.ec2SSH import Ec2SSH
vmms = Ec2SSH(job.accessKeyId, job.accessKey)
newVM = copy.deepcopy(job.vm)
newVM.id = self._getNextID()
preVM = vmms.initializeVM(newVM)
else:
# Try to find a vm on the free list and allocate it to
# the worker if successful.
if Config.REUSE_VMS:
preVM = vm
else:
# Try to find a vm on the free list and allocate it to
# the worker if successful.
if Config.REUSE_VMS:
preVM = vm
else:
preVM = self.preallocator.allocVM(job.vm.name)
vmms = self.vmms[job.vm.vmms] # Create new vmms object

# Now dispatch the job to a worker
preVM = self.preallocator.allocVM(job.vm.name)
vmms = self.vmms[job.vm.vmms] # Create new vmms object

if preVM.name is not None:
self.log.info("Dispatched job %s:%d to %s [try %d]" %
(job.name, job.id, preVM.name, job.retries))
job.appendTrace(
"%s|Dispatched job %s:%d [try %d]" %
(datetime.utcnow().ctime(), job.name, job.id, job.retries))

Worker(
job,
vmms,
self.jobQueue,
self.preallocator,
preVM
).start()

except Exception as err:
self.jobQueue.makeDead(job.id, str(err))

# Sleep for a bit and then check again
time.sleep(Config.DISPATCH_PERIOD)
else:
self.log.info("Unable to pre-allocate a vm for job job %s:%d [try %d]" % (job.name, job.id, job.retries))

job.appendTrace(
"%s|Dispatched job %s:%d [try %d]" %
(datetime.utcnow().ctime(), job.name, job.id, job.retries))

Worker(
job,
vmms,
self.jobQueue,
self.preallocator,
preVM
).start()

except Exception as err:
self.jobQueue.makeDead(job.id, str(err))


if __name__ == "__main__":
Expand Down
Loading