Skip to content

Commit

Permalink
Fixed location fetching in ScirSession for GCLOUD
Browse files Browse the repository at this point in the history
  • Loading branch information
prioux committed Feb 14, 2025
1 parent 7fcb9d4 commit 5334ce4
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions BrainPortal/lib/scir_gcloud_batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,23 @@ class ScirGcloudBatch < Scir

Revision_info=CbrainFileRevision[__FILE__] #:nodoc:

# Utility class method; given a from_string like
# "GCLOUD_PROJECT=abcde GCLOUD_IMAGE_BASENAME=baseim GCLOUD_LOCATION=westofhere"
# and a varname like "GCLOUD_PROJECT", this method returns the value, "abcde".
def self.extract_config_value(varname, from_string)
return nil if from_string.blank? || varname.blank?
search_val = Regexp.new('\b' + Regexp.escape(varname) + '\s*=\s*(\w[\.\w-]+)', Regexp::IGNORECASE)
return Regexp.last_match[1] if from_string.match(search_val)
nil
end

class Session < Scir::Session #:nodoc:

def update_job_info_cache #:nodoc:
out_text, err_text = bash_this_and_capture_out_err(
# the '%A' format returns the job ID
# the '%t' format returns the status with the one or two letter codes.
"gcloud batch jobs list --location #{gcloud_location()}"
"gcloud batch jobs list --location #{gcloud_location}"
)
raise "Cannot get output of 'squeue'" if err_text.present?
out_lines = out_text.split("\n")
Expand Down Expand Up @@ -83,9 +93,10 @@ def terminate(jid) #:nodoc:
return
end

# Fetches the location from the Bourreau level config; cannot fetch from tool config level
# within a ScirSession
def gcloud_location
#TODO better
"--location northamerica-northeast1"
ScirGcloudBatch.extract_config_value('GCLOUD_LOCATION', Scir.cbrain_config[:extra_qsub_args])
end

def queue_tasks_tot_max #:nodoc:
Expand Down Expand Up @@ -140,14 +151,9 @@ def get_config_value_from_extra_qsubs(varname)
value
end

# Given a from_string like
# "GCLOUD_PROJECT=abcde GCLOUD_IMAGE_BASENAME=baseim GCLOUD_LOCATION=westofhere"
# and a varname like "GCLOUD_PROJECT", this method returns the value, "abcde".
# just calls the utility in the main class
def extract_config_value(varname, from_string)
return nil if from_string.blank?
search_val = Regexp.new('\b' + Regexp.escape(varname) + '\s*=\s*(\w[\.\w-]+)', Regexp::IGNORECASE)
return Regexp.last_match[1] if from_string.match(search_val)
nil
ScirGcloudBatch.extract_config_value(varname, from_string)
end

def qsub_command #:nodoc:
Expand Down

0 comments on commit 5334ce4

Please sign in to comment.