Class: Aspera::Cli::AsyncTransferStore

Inherits:
Object
  • Object
show all
Defined in:
lib/aspera/cli/async_transfer_store.rb

Overview

Persist the state of asynchronous transfers on the local file system.

Each entry is a JSON document identified by a job_id (UUID generated by ascli). The underlying storage uses PersistencyFolder with the category prefix CATEGORY so all async-transfer files are grouped together and can be garbage-collected independently.

Schema of a stored entry:

job_id            [String]  UUID generated by ascli (= the store key)
agent_type        [String]  'desktop' | 'node' | 'connect' | 'transferd' | 'direct'
transfer_id       [String]  Opaque ID returned by the agent's start_transfer
agent_params      [Hash]    Agent-specific connection parameters for re-querying
status            [String]  'running' | 'completed' | 'failed' | 'cancelled'
bytes_transferred [Integer] Last known bytes transferred (0 if unknown)
started_at        [String]  ISO-8601 timestamp
ended_at          [String, nil] ISO-8601 timestamp once finished
error             [String, nil] Error message when status == 'failed'

Instance Method Summary collapse

Constructor Details

#initialize(persistency) ⇒ AsyncTransferStore

Returns a new instance of AsyncTransferStore.

Parameters:



31
32
33
# File 'lib/aspera/cli/async_transfer_store.rb', line 31

def initialize(persistency)
  @persistency = persistency
end

Instance Method Details

#delete(job_id) ⇒ Object

Delete one entry.

Parameters:



67
68
69
70
71
# File 'lib/aspera/cli/async_transfer_store.rb', line 67

def delete(job_id)
  Aspera.assert_type(job_id, String){'job_id'}
  @persistency.delete(store_key(job_id))
  nil
end

#listArray<Hash>

List all async transfer entries.

Returns:

  • (Array<Hash>)

    each entry includes the job_id field



57
58
59
60
61
62
63
# File 'lib/aspera/cli/async_transfer_store.rb', line 57

def list
  @persistency.current_items(CATEGORY).map do |key, raw|
    data = JSON.parse(raw)
    data['job_id'] ||= key.sub(CATEGORY, '')
    data
  end
end

#read(job_id) ⇒ Hash?

Read one entry.

Parameters:

Returns:

  • (Hash, nil)

    the stored data, or nil if not found



48
49
50
51
52
53
# File 'lib/aspera/cli/async_transfer_store.rb', line 48

def read(job_id)
  Aspera.assert_type(job_id, String){'job_id'}
  raw = @persistency.get(store_key(job_id))
  return if raw.nil?
  JSON.parse(raw)
end

#write(job_id, data) ⇒ Object

Persist (create or update) an async transfer entry.

Parameters:

  • job_id (String)

    the ascli-generated UUID

  • data (Hash)

    fields to store (will be JSON-serialised)



38
39
40
41
42
43
# File 'lib/aspera/cli/async_transfer_store.rb', line 38

def write(job_id, data)
  Aspera.assert_type(job_id, String){'job_id'}
  Aspera.assert_type(data, Hash){'data'}
  @persistency.put(store_key(job_id), JSON.generate(data))
  nil
end