Sha256: 4f4270316989ceb14b95e919d744b024a21abfdf258bb347884214db8507465a

Contents?: true

Size: 901 Bytes

Versions: 10

Compression:

Stored size: 901 Bytes

Contents

module MissionControl::Jobs::Server::Serializable
  extend ActiveSupport::Concern

  class_methods do
    # Loads a server from a locator string with the format +<application>:<server>+. For example:
    #
    #   bc4:resque_chicago
    #
    # When the +<server>+ fragment is omitted it will return the first server for the application.
    def from_global_id(global_id)
      app_id, server_id = global_id.split(":")

      application = MissionControl::Jobs.applications[app_id] or raise MissionControl::Jobs::Errors::ResourceNotFound, "No application with id #{app_id} found"
      server = server_id ? application.servers[server_id] : application.servers.first

      server or raise MissionControl::Jobs::Errors::ResourceNotFound, "No server for #{global_id} found"
    end
  end

  def to_global_id
    suffix = ":#{id}" if application.servers.many?
    "#{application&.id}#{suffix}"
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mission_control-jobs-0.6.0 lib/mission_control/jobs/server/serializable.rb
mission_control-jobs-0.5.0 lib/mission_control/jobs/server/serializable.rb
mission_control-jobs-0.4.0 lib/mission_control/jobs/server/serializable.rb
mission_control-jobs-0.3.3 lib/mission_control/jobs/server/serializable.rb
mission_control-jobs-0.3.2 lib/mission_control/jobs/server/serializable.rb
mission_control-jobs-0.3.1 lib/mission_control/jobs/server/serializable.rb
mission_control-jobs-0.3.0 lib/mission_control/jobs/server/serializable.rb
mission_control-jobs-0.2.2 lib/mission_control/jobs/server/serializable.rb
mission_control-jobs-0.2.1 lib/mission_control/jobs/server/serializable.rb
mission_control-jobs-0.2.0 lib/mission_control/jobs/server/serializable.rb