Add semaphore to method calls in DockerClient
This commit is contained in:
@ -306,7 +306,8 @@ class DockerClient
|
|||||||
Rails.logger.info('killing container ' + container.to_s)
|
Rails.logger.info('killing container ' + container.to_s)
|
||||||
# remove container from pool, then destroy it
|
# remove container from pool, then destroy it
|
||||||
if (DockerContainerPool.config[:active])
|
if (DockerContainerPool.config[:active])
|
||||||
DockerContainerPool.remove_from_all_containers(container, @execution_environment)
|
DockerContainerPool.semaphore.acquire
|
||||||
|
DockerContainerPool.remove_from_all_containers(container, @execution_environment, bypass_semaphore: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.class.destroy_container(container)
|
self.class.destroy_container(container)
|
||||||
@ -315,7 +316,8 @@ class DockerClient
|
|||||||
if(DockerContainerPool.config[:active] && RECYCLE_CONTAINERS)
|
if(DockerContainerPool.config[:active] && RECYCLE_CONTAINERS)
|
||||||
# create new container and add it to @all_containers and @containers.
|
# create new container and add it to @all_containers and @containers.
|
||||||
container = self.class.create_container(@execution_environment)
|
container = self.class.create_container(@execution_environment)
|
||||||
DockerContainerPool.add_to_all_containers(container, @execution_environment)
|
DockerContainerPool.add_to_all_containers(container, @execution_environment, bypass_semaphore: true)
|
||||||
|
DockerContainerPool.semaphore.release
|
||||||
end
|
end
|
||||||
exit_thread_if_alive
|
exit_thread_if_alive
|
||||||
end
|
end
|
||||||
@ -439,7 +441,8 @@ class DockerClient
|
|||||||
|
|
||||||
# remove container from pool, then destroy it
|
# remove container from pool, then destroy it
|
||||||
if (DockerContainerPool.config[:active])
|
if (DockerContainerPool.config[:active])
|
||||||
DockerContainerPool.remove_from_all_containers(container, @execution_environment)
|
DockerContainerPool.semaphore.acquire
|
||||||
|
DockerContainerPool.remove_from_all_containers(container, @execution_environment, bypass_semaphore: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
# destroy container
|
# destroy container
|
||||||
@ -449,7 +452,8 @@ class DockerClient
|
|||||||
if(DockerContainerPool.config[:active] && RECYCLE_CONTAINERS)
|
if(DockerContainerPool.config[:active] && RECYCLE_CONTAINERS)
|
||||||
# create new container and add it to @all_containers and @containers.
|
# create new container and add it to @all_containers and @containers.
|
||||||
container = self.class.create_container(@execution_environment)
|
container = self.class.create_container(@execution_environment)
|
||||||
DockerContainerPool.add_to_all_containers(container, @execution_environment)
|
DockerContainerPool.add_to_all_containers(container, @execution_environment, bypass_semaphore: true)
|
||||||
|
DockerContainerPool.semaphore.release
|
||||||
end
|
end
|
||||||
{status: :timeout}
|
{status: :timeout}
|
||||||
end
|
end
|
||||||
|
@ -36,6 +36,10 @@ class DockerContainerPool
|
|||||||
@all_containers
|
@all_containers
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.semaphore
|
||||||
|
@semaphore
|
||||||
|
end
|
||||||
|
|
||||||
def self.remove_from_all_containers(container, execution_environment, bypass_semaphore: false)
|
def self.remove_from_all_containers(container, execution_environment, bypass_semaphore: false)
|
||||||
@semaphore.acquire unless bypass_semaphore
|
@semaphore.acquire unless bypass_semaphore
|
||||||
@all_containers[execution_environment.id] -= [container]
|
@all_containers[execution_environment.id] -= [container]
|
||||||
|
Reference in New Issue
Block a user