Module: OodCore::Job::Adapters::Flux::JobId Private

Defined in:
lib/ood_core/job/adapters/flux/job_id.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Convert Flux job ids to decimal. Flux prints ids in F58 (RFC 19), base58 with a "ƒ" prefix; OnDemand stores and returns them in decimal.

Written in the compact form so this file never reopens class Flux. It is required from inside the Flux class body, after the class exists.

Constant Summary collapse

F58_ALPHABET =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The base58 alphabet Flux uses for F58 ids (RFC 19)

"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".freeze
F58_PREFIX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Flux prefixes F58 ids with "ƒ", or "f" when the locale isn't UTF-8

/\A[ƒf]/.freeze

Class Method Summary collapse

Class Method Details

.to_decimal(id) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the job id in decimal.

Parameters:

  • id (#to_s) —

    a job id in decimal or F58

Returns:

  • (String) —

    the job id in decimal



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ood_core/job/adapters/flux/job_id.rb', line 17

def self.to_decimal(id)
  str = id.to_s.dup.force_encoding(Encoding::UTF_8).strip
  return str if str.match?(/\A\d+\z/)

  unless str.match?(F58_PREFIX)
    raise OodCore::Job::Adapters::Flux::Batch::Error, "unrecognized flux job id: #{str.inspect}"
  end

  digits = str.sub(F58_PREFIX, "")
  number = 0
  digits.each_char do |char|
    value = F58_ALPHABET.index(char)
    raise OodCore::Job::Adapters::Flux::Batch::Error, "unrecognized flux job id: #{str.inspect}" if value.nil?

    number = (number * 58) + value
  end
  number.to_s
end