lib/coursemology/evaluator/docker_container.rb in coursemology-evaluator-0.1.3 vs lib/coursemology/evaluator/docker_container.rb in coursemology-evaluator-0.1.4
- old
+ new
@@ -13,14 +13,33 @@
end
end
private
+ # Pulls the given image from Docker Hub.
+ #
+ # This caches images for 5 minutes, because the overhead for querying for images is quite high.
+ #
+ # @param [String] image The image to pull.
def pull_image(image)
ActiveSupport::Notifications.instrument('pull.docker.evaluator.coursemology',
- image: image) do
- Docker::Image.create('fromImage' => image)
+ image: image) do |payload|
+ cached([:image, image], expires_in: 5.minutes) do
+ Docker::Image.create('fromImage' => image)
+ payload[:cached] = false
+ end
end
+ end
+
+ # Cache the result of the given block using the key given.
+ #
+ # @param [Array, String, Symbol] key The key to use. This will be expanded with
+ # +ActiveSupport::Cache.expand_cache_key+.
+ # @param [Hash] options The options to use. These are the same as
+ # +ActiveSupport::Cache::Store#fetch+.
+ def cached(key, options = {}, &proc)
+ key = ActiveSupport::Cache.expand_cache_key(key, name.underscore)
+ Coursemology::Evaluator.cache.fetch(key, options, &proc)
end
end
# Waits for the container to exit the Running state.
#