foreman_remote_execution 1.5.5 → 1.5.6

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
  SHA256:
3
- metadata.gz: 9494abeb23995efb0f837561fd1b1bd84fbd7ef37060081ea573d2dde16bd74b
4
- data.tar.gz: afbf23769a88fecbbcb7197249b2261a046b568be38699c35a12210ab6cb13e5
3
+ metadata.gz: e46050a5990faad87a961e071259349d70484bd1a3a5dc591f2dc2d99a8ed5fd
4
+ data.tar.gz: 2024c485f96831c771299629dee1eae498fbc078cd9a97fded7db60a66c88b4f
5
5
  SHA512:
6
- metadata.gz: 28dd96a2c75c9e94f71a6613fac13ecbf7938d46fdfc0d5208833073149a3e60c84de6a7ee357ca22318abae29a7deb85afb77377ff462ee71aade08cf7ec0ca
7
- data.tar.gz: 5d012baa162db923230e7d7c0f0dc03a315075ce79f3bc64b8cc1236c328061c2ff839f97c56849157c303fc5e758376ecab15d65137cf206aabe6159d7025cf
6
+ metadata.gz: fc474783987a76f8fa74304887f7a54aba2d1a4a64619087d891266916cff2f9c4527e2a53fff719bf8736f10d9fbf8542da2d99cd78d87d946f1048965c24a8
7
+ data.tar.gz: af6e2aa4211743d8e210f2dfc823f81110ff6100ba4cb046b90ab85ca8a13048e6087eaaeebe9d856112cd525b2ae957e5d112a5734d96754fc77013b51b4cd7
@@ -49,6 +49,8 @@ module Actions
49
49
  job_invocation.password = job_invocation.key_passphrase = job_invocation.sudo_password = nil
50
50
  job_invocation.save!
51
51
 
52
+ Rails.logger.debug "cleaning cache for keys that begin with 'job_invocation_#{job_invocation.id}'"
53
+ Rails.cache.delete_matched(/\A#{JobInvocation::CACHE_PREFIX}_#{job_invocation.id}/)
52
54
  # creating the success notification should be the very last thing this tasks do
53
55
  job_invocation.build_notification.deliver!
54
56
  end
@@ -25,7 +25,7 @@ class InputTemplateRenderer
25
25
 
26
26
  def render
27
27
  @template.validate_unique_inputs!
28
- render_safe(@template.template, ::Foreman::Renderer::ALLOWED_HELPERS + [ :input, :render_template, :preview?, :render_error ], :host => @host)
28
+ render_safe(@template.template, ::Foreman::Renderer::ALLOWED_HELPERS + [ :input, :render_template, :preview?, :render_error, :cached ], :host => @host)
29
29
  rescue => e
30
30
  self.error_message ||= _('error during rendering: %s') % e.message
31
31
  Rails.logger.debug e.to_s + "\n" + e.backtrace.join("\n")
@@ -40,6 +40,13 @@ class InputTemplateRenderer
40
40
  @preview = old_preview
41
41
  end
42
42
 
43
+ def cached(key, &block)
44
+ return yield if preview?
45
+ cache_key = "#{JobInvocation::CACHE_PREFIX}_#{invocation.job_invocation_id}_#{key}"
46
+ Rails.logger.debug "cache hit for #{cache_key}" if Rails.cache.exist?(cache_key)
47
+ Rails.cache.fetch(cache_key, &block)
48
+ end
49
+
43
50
  def input(name)
44
51
  return @input_values[name.to_s] if @input_values
45
52
  input = find_by_name(@template.template_inputs_with_foreign, name) # rubocop:disable Rails/DynamicFindBy
@@ -1,4 +1,6 @@
1
1
  class JobInvocation < ApplicationRecord
2
+ CACHE_PREFIX = "job_invocation".freeze
3
+
2
4
  audited :except => [:task_id, :targeting_id, :task_group_id, :triggering_id]
3
5
 
4
6
  include Authorizable
@@ -1,3 +1,3 @@
1
1
  module ForemanRemoteExecution
2
- VERSION = '1.5.5'.freeze
2
+ VERSION = '1.5.6'.freeze
3
3
  end
@@ -39,6 +39,36 @@ class InputTemplateRendererTest < ActiveSupport::TestCase
39
39
  renderer.error_message.wont_be_empty
40
40
  end
41
41
  end
42
+
43
+ describe 'caching helper' do
44
+ it 'caches the value under given key in real mode' do
45
+ renderer.stubs(:invocation => OpenStruct.new(:job_invocation_id => 1))
46
+
47
+ i = 1
48
+ result = renderer.cached('some_key') { i }
49
+ result.must_equal 1
50
+ i += 1
51
+ result = renderer.cached('some_key') { i }
52
+ result.must_equal 1
53
+ i += 1
54
+ result = renderer.cached('different_key') { i }
55
+ result.must_equal 3
56
+ end
57
+
58
+ it 'does not cache the value in preview mode' do
59
+ renderer.stubs(:invocation => OpenStruct.new(:job_invocation_id => 1), :preview? => true)
60
+
61
+ i = 1
62
+ result = renderer.cached('some_key') { i }
63
+ result.must_equal 1
64
+ i += 1
65
+ result = renderer.cached('some_key') { i }
66
+ result.must_equal 2
67
+ i += 1
68
+ result = renderer.cached('different_key') { i }
69
+ result.must_equal 3
70
+ end
71
+ end
42
72
  end
43
73
 
44
74
  context 'with matching input defined' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_remote_execution
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.5
4
+ version: 1.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman Remote Execution team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-14 00:00:00.000000000 Z
11
+ date: 2018-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface