OOD 1.1.5 - Custom checkbox for exclusivity

I’m trying to configure a checkbox for some of my applications for users to request exclusive use of a node for running his/her Slurm job (i.e., the --exclusive option for sbatch.) I’ve been able to get the checkbox to appear on the submission form, but when I attempt to submit the job, I get errors. I am sure it’s because I don’t know what to put in my submit.yml.erb file, having been unable to find an example in Discourse that appears relevant. I’ve tried several different things, but here is my latest failure, which results in an Internal Server Error:

---
batch_connect:
  template: vnc
script:
  queue_name: <%= custom_queue %>
  native:
    - "-N"
    - "<%= bc_num_slots.blank? ? 1 : bc_num_slots.to_i %>"
    - "--ntasks-per-node"
    - "<%= bc_num_cores.blank? ? 1 : bc_num_cores.to_i %>"
    - "--mem"
    - "<%= bc_num_memory.blank? ? 6144 : bc_num_memory.to_i*1024 %>"
    - "--exclusive"
    - "<%= ! bc_exclusive.to_i.zero? ? 1 %><% unless bc_exclusive.blank %>"

What do I need to do differently?

Thanks!

In this case I think we only want the flag added if bc_exclusive.to_i == 1. If checked, we include - "--exclusive":

---
batch_connect:
  template: vnc
script:
  queue_name: <%= custom_queue %>
  native:
    - "-N"
    - "<%= bc_num_slots.blank? ? 1 : bc_num_slots.to_i %>"
    - "--ntasks-per-node"
    - "<%= bc_num_cores.blank? ? 1 : bc_num_cores.to_i %>"
    - "--mem"
    - "<%= bc_num_memory.blank? ? 6144 : bc_num_memory.to_i*1024 %>"
    <%= '- "--exclusive"' if bc_exclusive.to_i == 1 %>

Notice the <%= is lined up with the previous line’s -. You might also be able to do either of these below, though I wasn’t able to test this successfully from the command line, because Rails adds these extra tags.

    - "--mem"
    - "<%= bc_num_memory.blank? ? 6144 : bc_num_memory.to_i*1024 %>"
    <%= '- "--exclusive"' if bc_exclusive.to_i == 1 -%>
  • using -%> instead of %>

or

    - "--mem"
    - "<%= bc_num_memory.blank? ? 6144 : bc_num_memory.to_i*1024 %>"
    <%- if bc_exclusive.to_i == 1 -%>
    - "--exclusive"
    <%- end -%>
  • more readable, and I think the <%- and -%> would prevent the extra whitespace

Clearly, I’m going to have to take some time to learn to write YAML code. With my current rudimentary knowledge, I wouldn’t have figured out the syntax you’ve shared, so I’m much obliged. I went with the second suggestion (I like “more readable”), and it works like a charm.

Thank you and the rest of the OOD community for your patience and support. I do believe I’m going to meet my deadline, which is tomorrow afternoon.