add limit for borrowing machine: runtime <= 10 days
only jobs that runtime value is less than or equal to 10 days are allowed for borrowing machine.
Signed-off-by: Luan Shengde shdluan@163.com --- src/lib/job.cr | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/src/lib/job.cr b/src/lib/job.cr index 89c92c1..61f18d6 100644 --- a/src/lib/job.cr +++ b/src/lib/job.cr @@ -143,6 +143,7 @@ class Job
check_required_keys() check_account_info() + check_run_time() set_defaults() end
@@ -401,6 +402,20 @@ class Job @hash.delete("my_token") end
+ private def check_run_time + # only job.yaml for borrowing machine has the key: ssh_pub_key + return unless @hash.has_key?("ssh_pub_key") + + # runtime value is converted to second. + max_run_time = 10 * 24 * 3600 + + error_msg = "The maximum runtime should no more than 10 days." + + # case runtime/sleep value count is more than 10 days, job will fail. + raise error_msg if @hash["runtime"].to_i > max_run_time + raise error_msg if @hash["sleep"].to_i > max_run_time + end + private def is_valid_account?(account_info) return false unless account_info.is_a?(JSON::Any)
- error_msg = "The maximum runtime should no more than 10 days."
=> Machine borrow time cannot exceed 10 days. Consider re-borrow.
- # case runtime/sleep value count is more than 10 days, job will fail.
- raise error_msg if @hash["runtime"].to_i > max_run_time
Better test pp.sleep.runtime to catch this situation:
sleep: runtime: xx
- raise error_msg if @hash["sleep"].to_i > max_run_time
- end
- private def is_valid_account?(account_info) return false unless account_info.is_a?(JSON::Any)
-- 2.23.0