coursemology-evaluator 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2361d90ee822c05a9e26b9217eeaa788326d1119
4
- data.tar.gz: 3bcad2014eecd4ea44c79ea5a3855fc1d894ef44
3
+ metadata.gz: fb396ac979a791b3d79224f80b88fa8ffb60b142
4
+ data.tar.gz: d3fd4e275fea14998d7b66a61c36f935f78f85a9
5
5
  SHA512:
6
- metadata.gz: 75fa50f0c17da2ed28a29a6384a58c47dffd23158ff924cd65983e243fa2c8f3b9c76721c5b19a3108c094b3bbc795fc25a58b5b5f18a12b50b0a2696273eb60
7
- data.tar.gz: 5cc695d5a5eb9fccc4c9217474dde9bae852e6ae8df03d55bc10464b02e4ac7b04626b6fcc374ff62bf78a6f124140bba6ca008f910af921f9bd4d645135fa35
6
+ metadata.gz: 3d33529e852271ea6c3a81e5e2c0732aea4614623bf550d0dc4ac40740b23d8659b9eaec7a516eedf1c7367af6563353ad9de799f7387687b917c2fce0f0b8a6
7
+ data.tar.gz: 886203828c1fb1dcc2a42ede52600b23837523ad9ca41594d7322406cec834bdf3b8c8cafac77741bbcfc8e25900b12d06fe41631d5d4942cd30716525588e94
@@ -28,6 +28,9 @@ module Coursemology::Evaluator
28
28
  # The logger to use for the client.
29
29
  mattr_reader(:logger) { ActiveSupport::Logger.new(STDOUT) }
30
30
 
31
+ # The cache to use for the client.
32
+ mattr_reader(:cache) { ActiveSupport::Cache.lookup_store }
33
+
31
34
  def self.eager_load!
32
35
  super
33
36
  Coursemology::Polyglot.eager_load!
@@ -15,25 +15,28 @@ class Coursemology::Evaluator::Client
15
15
 
16
16
  def run
17
17
  Signal.trap('SIGTERM', method(:on_sig_term))
18
+ loop(&method(:client_loop))
19
+ end
18
20
 
19
- loop do
20
- evaluations = allocate_evaluations
21
+ private
21
22
 
22
- if evaluations && !evaluations.empty?
23
- on_allocate(evaluations)
24
- else
25
- # :nocov:
26
- # This sleep might not be triggered in the specs, because interruptions to the thread is
27
- # nondeterministically run by the OS scheduler.
28
- sleep(1.minute)
29
- # :nocov:
30
- end
23
+ # Performs one iteration of the client loop.
24
+ def client_loop
25
+ evaluations = allocate_evaluations
26
+ if evaluations && !evaluations.empty?
27
+ on_allocate(evaluations)
28
+ else
29
+ raise StopIteration if @terminate
31
30
 
32
- break if @terminate
31
+ # :nocov:
32
+ # This sleep might not be triggered in the specs, because interruptions to the thread is
33
+ # nondeterministically run by the OS scheduler.
34
+ sleep(1.minute)
35
+ # :nocov:
33
36
  end
34
- end
35
37
 
36
- private
38
+ raise StopIteration if @terminate
39
+ end
37
40
 
38
41
  # Requests evaluations from the server.
39
42
  #
@@ -15,12 +15,31 @@ class Coursemology::Evaluator::DockerContainer < Docker::Container
15
15
 
16
16
  private
17
17
 
18
+ # Pulls the given image from Docker Hub.
19
+ #
20
+ # This caches images for 5 minutes, because the overhead for querying for images is quite high.
21
+ #
22
+ # @param [String] image The image to pull.
18
23
  def pull_image(image)
19
24
  ActiveSupport::Notifications.instrument('pull.docker.evaluator.coursemology',
20
- image: image) do
21
- Docker::Image.create('fromImage' => image)
25
+ image: image) do |payload|
26
+ cached([:image, image], expires_in: 5.minutes) do
27
+ Docker::Image.create('fromImage' => image)
28
+ payload[:cached] = false
29
+ end
22
30
  end
23
31
  end
32
+
33
+ # Cache the result of the given block using the key given.
34
+ #
35
+ # @param [Array, String, Symbol] key The key to use. This will be expanded with
36
+ # +ActiveSupport::Cache.expand_cache_key+.
37
+ # @param [Hash] options The options to use. These are the same as
38
+ # +ActiveSupport::Cache::Store#fetch+.
39
+ def cached(key, options = {}, &proc)
40
+ key = ActiveSupport::Cache.expand_cache_key(key, name.underscore)
41
+ Coursemology::Evaluator.cache.fetch(key, options, &proc)
42
+ end
24
43
  end
25
44
 
26
45
  # Waits for the container to exit the Running state.
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
  class Coursemology::Evaluator::Logging::DockerLogSubscriber < ActiveSupport::LogSubscriber
3
3
  def pull(event)
4
- info "#{color("Docker Pull (#{event.duration.round(1)}ms)", GREEN)} #{event.payload[:image]}"
4
+ cached = event.payload[:cached].nil? || event.payload[:cached] ? 'Cached ' : ''
5
+ header_colour = cached ? GREEN : YELLOW
6
+ info "#{color("#{cached}Docker Pull (#{event.duration.round(1)}ms)", header_colour)} "\
7
+ "#{event.payload[:image]}"
5
8
  end
6
9
 
7
10
  def create(event)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Coursemology; end
3
3
  module Coursemology::Evaluator
4
- VERSION = '0.1.3'.freeze
4
+ VERSION = '0.1.4'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coursemology-evaluator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Low
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-01 00:00:00.000000000 Z
11
+ date: 2016-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler