Class: Agent::Lock::CLI::Commands::SwitchBackend

Inherits:
Base
  • Object
show all
Defined in:
lib/agent/lock/cli/commands/switch_backend.rb

Overview

Move a checkout's locks to the other backend.

The backend marker binds a checkout to the store it used first, so that two agents beside each other never use two stores. Releasing every lock did not move it, so the one way out used to be deleting the marker by hand. This is that, done safely.

A Base, not a TreeCommand: the backend is the argument, so a --locking-strategy beside it would be a second answer to the same question.

Instance Attribute Summary

Attributes inherited from Base

#launcher

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Agent::Lock::CLI::Commands::Base

Instance Method Details

#call(backend:, **options) ⇒ Manager::Result?

Returns nil when the tree was bound to nothing yet, or to a Redis that does not answer.

Parameters:

  • backend (String) —

    as typed

  • options (Hash) —

    :dir, :redis_url, :discard_locks

Returns:

  • (Manager::Result, nil) —

    nil when the tree was bound to nothing yet, or to a Redis that does not answer

Raises:

  • (Store::Unreachable) —

    when the tree is bound to a Redis that does not answer, and :discard_locks is not set



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/agent/lock/cli/commands/switch_backend.rb', line 39

def call(backend:, **options)
  tree = Tree.for(options[:dir] || ".")
  target = target_store(tree, backend, options[:redis_url])
  current, unread = current_store(tree)
  return leave_unread(tree, target, unread, options) if unread
  return bind_virgin(tree, target) if current.nil?

  result = Manager.new(tree: tree, store: current).switch_backend(target, discard: options[:discard_locks])
  report(result, from: current.backend, to: target.backend, url: options[:redis_url])
  finish(result)
end