Module: Agent::Lock

Defined in:
lib/agent/lock.rb,
lib/agent/lock/cli.rb,
lib/agent/lock/cli.rb,
lib/agent/lock/text.rb,
lib/agent/lock/tree.rb,
lib/agent/lock/error.rb,
lib/agent/lock/scope.rb,
lib/agent/lock/skill.rb,
lib/agent/lock/store.rb,
lib/agent/lock/facade.rb,
lib/agent/lock/freeze.rb,
lib/agent/lock/record.rb,
lib/agent/lock/manager.rb,
lib/agent/lock/version.rb,
lib/agent/lock/identity.rb,
lib/agent/lock/launcher.rb,
lib/agent/lock/facade/memo.rb,
lib/agent/lock/facade/async.rb,
lib/agent/lock/manager/thaw.rb,
lib/agent/lock/process_info.rb,
lib/agent/lock/facade/backend.rb,
lib/agent/lock/facade/refusal.rb,
lib/agent/lock/facade/session.rb,
lib/agent/lock/manager/switch.rb,
lib/agent/lock/cli/commands/base.rb,
lib/agent/lock/cli/commands/list.rb,
lib/agent/lock/cli/commands/mine.rb,
lib/agent/lock/cli/commands/note.rb,
lib/agent/lock/cli/commands/show.rb,
lib/agent/lock/facade/strategies.rb,
lib/agent/lock/store/redis_index.rb,
lib/agent/lock/store/redis_store.rb,
lib/agent/lock/cli/commands/break.rb,
lib/agent/lock/cli/commands/check.rb,
lib/agent/lock/store/backend_name.rb,
lib/agent/lock/cli/commands/resume.rb,
lib/agent/lock/cli/commands/skills.rb,
lib/agent/lock/cli/commands/whoami.rb,
lib/agent/lock/manager/enforcement.rb,
lib/agent/lock/cli/commands/acquire.rb,
lib/agent/lock/cli/commands/listing.rb,
lib/agent/lock/cli/commands/release.rb,
lib/agent/lock/cli/commands/version.rb,
lib/agent/lock/cli/commands/completion.rb,
lib/agent/lock/store/file_system_store.rb,
lib/agent/lock/cli/commands/release_all.rb,
lib/agent/lock/cli/commands/tree_command.rb,
lib/agent/lock/process_info/legacy_start.rb,
lib/agent/lock/cli/commands/switch_backend.rb

Overview

Facade and the process-wide facades Lock.local and Lock.distributed.

Defined Under Namespace

Modules: CLI, Freeze, ProcessInfo, Store, Text Classes: Error, Facade, Identity, Launcher, Manager, Record, RedisUnavailableError, Refused, Scope, Skill, Tree

Constant Summary collapse

VERSION =

The gem's version, read by the gemspec and printed by alock version.

"4.0.0"

Class Method Summary collapse

Class Method Details

.distributed(redis_url: nil) ⇒ Facade

The process-wide Redis facade for one Redis, built on first use and kept per URL, so a host whose Redis comes from its own flag or config file gets the same locker on every call. Thread-safe. A failed build is not kept: the next call tries Redis again.

Parameters:

  • redis_url (String, nil) (defaults to: nil) —

    nil resolves as Agent::Lock::Facade.redis_url says: AGENT_LOCK_REDIS_URL, then REDIS_URL, then the default

Returns:

Raises:



338
339
340
341
342
343
# File 'lib/agent/lock/facade.rb', line 338

def distributed(redis_url: nil)
  url = Facade.redis_url(redis_url)
  DISTRIBUTED_MUTEX.synchronize do
    DISTRIBUTED_FACADES.value[url] ||= Facade.new(strategies: %w[redis], redis_url: url)
  end
end

.facade(strategies: Facade::DEFAULT_STRATEGIES, redis_url: nil, async: false, **defaults) ⇒ Facade

A new facade, defaulting like alock: Redis when it answers, the file store when it does not. Never memoized.

Parameters:

Returns:



354
355
356
# File 'lib/agent/lock/facade.rb', line 354

def facade(strategies: Facade::DEFAULT_STRATEGIES, redis_url: nil, async: false, **defaults)
  Facade.new(strategies:, redis_url:, async:, **defaults)
end

.local ⇒ Facade

The process-wide file-store facade, built on first use. Thread-safe, and independent of distributed and of every Facade.new.

Returns:



327
# File 'lib/agent/lock/facade.rb', line 327

def local = LOCAL_FACADE.value

.reset_facades! ⇒ void

This method returns an undefined value.

Forget local and distributed, so the next call builds each anew. For tests. A process whose REDIS_URL changed needs no reset: the new URL is a new facade.



363
364
365
366
# File 'lib/agent/lock/facade.rb', line 363

def reset_facades!
  LOCAL_FACADE.reset
  DISTRIBUTED_FACADES.reset
end