Class: RServiceBus2::SagaStorageDir
- Inherits:
-
Object
- Object
- RServiceBus2::SagaStorageDir
- Defined in:
- lib/rservicebus2/saga_storage/dir.rb
Overview
Saga Storage Dir
Instance Method Summary collapse
-
#begin ⇒ Object
Start.
-
#commit ⇒ Object
Finish.
- #delete(correlation_id) ⇒ Object
-
#get(correlation_id) ⇒ Object
Get.
-
#get_path(correlation_id) ⇒ Object
Detail Functions.
-
#initialize(uri) ⇒ SagaStorageDir
constructor
A new instance of SagaStorageDir.
- #load(path) ⇒ Object
- #rollback ⇒ Object
-
#set(data) ⇒ Object
Set.
Constructor Details
#initialize(uri) ⇒ SagaStorageDir
Returns a new instance of SagaStorageDir.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rservicebus2/saga_storage/dir.rb', line 4 def initialize(uri) @saga_dir = uri.path Dir.new(@saga_dir) unless File.writable?(@saga_dir) puts "***** Directory is not writable, #{@saga_dir}." puts "***** Make the directory, #{@saga_dir}, writable and try again." puts '***** Or, set the Saga Directory explicitly by, SAGA_URI=<dir://path/to/saga>' abort end rescue Errno::ENOENT puts "***** Directory does not exist, #{@saga_dir}." puts "***** Create the directory, #{@saga_dir}, and try again." puts "***** eg, mkdir #{@saga_dir}" puts '***** Or, set the Saga Directory explicitly by, SAGA_URI=<dir://path/to/saga>' abort rescue Errno::ENOTDIR puts "***** The specified path does not point to a directory, #{@saga_dir}." puts "***** Either repoint path to a directory, or remove, #{@saga_dir}, and create it as a directory." puts "***** eg, rm #{@saga_dir} && mkdir #{@saga_dir}" puts '***** Or, set the Saga Directory explicitly by, SAGA_URI=<dir://path/to/saga>' abort end |
Instance Method Details
#begin ⇒ Object
Start
34 35 36 37 |
# File 'lib/rservicebus2/saga_storage/dir.rb', line 34 def begin @list = [] @deleted = [] end |
#commit ⇒ Object
Finish
55 56 57 58 59 60 61 62 |
# File 'lib/rservicebus2/saga_storage/dir.rb', line 55 def commit @list.each do |e| File.open(e['path'], 'w') { |f| f.write(YAML.dump(e['data'])) } end @deleted.each do |correlation_id| File.unlink(get_path(correlation_id)) end end |
#delete(correlation_id) ⇒ Object
67 68 69 |
# File 'lib/rservicebus2/saga_storage/dir.rb', line 67 def delete(correlation_id) @deleted << correlation_id end |
#get(correlation_id) ⇒ Object
Get
46 47 48 49 50 51 52 |
# File 'lib/rservicebus2/saga_storage/dir.rb', line 46 def get(correlation_id) path = get_path(correlation_id) data = load(path) @list << Hash['path', path, 'data', data] data end |
#get_path(correlation_id) ⇒ Object
Detail Functions
72 73 74 |
# File 'lib/rservicebus2/saga_storage/dir.rb', line 72 def get_path(correlation_id) "#{@saga_dir}/saga-#{correlation_id}" end |
#load(path) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/rservicebus2/saga_storage/dir.rb', line 76 def load(path) return {} unless File.exist?(path) content = IO.read(path) return {} if content == '' YAML.load(content) end |
#rollback ⇒ Object
64 65 |
# File 'lib/rservicebus2/saga_storage/dir.rb', line 64 def rollback end |
#set(data) ⇒ Object
Set
40 41 42 43 |
# File 'lib/rservicebus2/saga_storage/dir.rb', line 40 def set(data) path = get_path(data.correlation_id) @list << Hash['path', path, 'data', data] end |