Skip to content

Commit cc24511

Browse files
authored
Separate launcher cache from workflows (#5019)
* adds launcher attribute for `cacheless_attributes` * uses `cacheless_attributes` for form editor and workflow submission * prevents workflow runs from writing new caches
1 parent 8e4c4cd commit cc24511

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

apps/dashboard/app/models/launcher.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Launcher
77

88
class ClusterNotFound < StandardError; end
99

10-
attr_reader :title, :id, :created_at, :project_dir, :smart_attributes
10+
attr_reader :title, :id, :created_at, :project_dir, :cacheless_attributes, :smart_attributes
1111

1212
class << self
1313
def launchers_dir(project_dir)
@@ -78,14 +78,20 @@ def initialize(opts = {})
7878
add_required_fields(**sm_opts)
7979
# add defaults if it's a brand new launcher with only title and directory.
8080
add_default_fields(**sm_opts) if opts.size <= 2
81+
82+
# we generate two sets of attributes here depending on whether we want the initial
83+
# form values to come from the form defaults or from the cache.
84+
@cacheless_attributes = build_smart_attributes(**sm_opts, use_cache: false)
8185
@smart_attributes = build_smart_attributes(**sm_opts)
8286
end
8387

84-
def build_smart_attributes(form: [], attributes: {})
88+
def build_smart_attributes(form: [], attributes: {}, use_cache: true)
8589
form.map do |form_item_id|
8690
attrs = attributes[form_item_id.to_sym].to_h.symbolize_keys
87-
cache_value = cached_values[form_item_id]
88-
attrs[:value] = cache_value if cache_value.present?
91+
if use_cache
92+
cache_value = cached_values[form_item_id]
93+
attrs[:value] = cache_value if cache_value.present?
94+
end
8995
SmartAttributes::AttributeFactory.build(form_item_id, attrs)
9096
end
9197
end
@@ -190,7 +196,7 @@ def update(params)
190196
update_attributes(params)
191197
end
192198

193-
def submit(options)
199+
def submit(options, write_cache: true)
194200
cluster_id = if options.has_key?(:auto_batch_clusters)
195201
options[:auto_batch_clusters]
196202
else
@@ -206,7 +212,7 @@ def submit(options)
206212
adapter.submit(job_script, **dependency_helper(options))
207213
end
208214
update_job_log(job_id, cluster_id.to_s)
209-
write_job_options_to_cache(options)
215+
write_job_options_to_cache(options) if write_cache
210216

211217
job_id
212218
rescue StandardError => e

apps/dashboard/app/models/workflow.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def submit(attributes = {})
154154
begin
155155
jobs = dependent_launchers.map { |id| job_id_hash.dig(id, :job_id) }.compact
156156
opts = submit_launcher_params(launcher, jobs).to_h.symbolize_keys
157-
job_id = launcher.submit(opts)
157+
job_id = launcher.submit(opts, write_cache: false)
158158
if job_id.nil?
159159
Rails.logger.warn("Launcher #{id} with opts #{opts} did not return a job ID.")
160160
else
@@ -174,11 +174,11 @@ def submit(attributes = {})
174174
end
175175

176176
def submit_launcher_params(launcher, dependent_jobs)
177-
launcher_data = launcher.smart_attributes.each_with_object({}) do |attr, hash|
177+
launcher_data = launcher.cacheless_attributes.each_with_object({}) do |attr, hash|
178178
hash[attr.id.to_s] = attr.opts[:value]
179179
end
180180
launcher_data["afterok"] = Array(dependent_jobs)
181181
launcher_data
182182
end
183183

184-
end
184+
end

apps/dashboard/app/views/launchers/edit.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<%= javascript_include_tag 'launcher_edit', nonce: true %>
44

55
<%= bootstrap_form_for(@launcher, url: save_project_launcher_path, html: { autocomplete: "off" }) do |f| %>
6-
<% @launcher.smart_attributes.each do |attrib| %>
6+
<% @launcher.cacheless_attributes.each do |attrib| %>
77
<%# TODO generate render_format %>
88
<%= create_editable_widget(f, attrib, format: nil) %>
99
<% end %>

0 commit comments

Comments
 (0)