Class: Ruote::FsStorage

Inherits:
Object
  • Object
show all
Includes:
StorageBase
Defined in:
lib/ruote/storage/fs_storage.rb

Overview

A basic FS-bound ruote storage. Leverages rufus-cloche (github.com/jmettraux/rufus-cloche).

Warning : for JRuby 1.4.0 on Ubuntu, passing the cloche_nolock option set to true seems necessary. See groups.google.com/group/openwferu-users/t/d82516ed3bdd8f23

Instance Method Summary collapse

Methods included from StorageBase

#clear, #context, #context=, #copy_to, #delete_schedule, #empty?, #expression_wfids, #find_root_expression, #get_configuration, #get_engine_variable, #get_msgs, #get_schedules, #get_trackers, #put_engine_variable, #put_msg, #put_schedule, #replace_engine_configuration, #reserve

Constructor Details

#initialize(dir, options = {}) ⇒ FsStorage

Creates a FsStorage pointing to the given dir.

The options are classical engine configuration, but the ‘cloche_nolock’ option is read by the storage and followed.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/ruote/storage/fs_storage.rb', line 54

def initialize(dir, options={})

  if dir.is_a?(Hash) && options == {}
    options = dir
    dir = options.delete('dir')
  end

  FileUtils.mkdir_p(dir)

  @cloche = Rufus::Cloche.new(
    :dir => dir, :nolock => options['cloche_nolock'])

  #@options = options

  replace_engine_configuration(options)
end

Instance Method Details

#add_type(type) ⇒ Object

No need for that here (FsStorage adds type on the fly).



111
112
# File 'lib/ruote/storage/fs_storage.rb', line 111

def add_type(type)
end

#delete(doc) ⇒ Object



81
82
83
84
# File 'lib/ruote/storage/fs_storage.rb', line 81

def delete(doc)

  @cloche.delete(doc)
end

#dump(type) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/ruote/storage/fs_storage.rb', line 119

def dump(type)

  s = "=== #{type} ===\n"

  @cloche.get_many(type).inject(s) do |s1, e|
    s1 << "\n"
    e.keys.sort.inject(s1) do |s2, k|
      s2 << "  #{k} => #{e[k].inspect}\n"
    end
  end
end

#get(type, key) ⇒ Object



76
77
78
79
# File 'lib/ruote/storage/fs_storage.rb', line 76

def get(type, key)

  @cloche.get(type, key)
end

#get_many(type, key = nil, opts = {}) ⇒ Object



86
87
88
89
90
91
92
93
94
95
# File 'lib/ruote/storage/fs_storage.rb', line 86

def get_many(type, key=nil, opts={})

  if key
    key = Array(key)
    key = key.map { |k| "!#{k}" } if key.first.is_a?(String)
  end
    # assuming /!#{wfid}$/...

  @cloche.get_many(type, key, opts)
end

#ids(type) ⇒ Object



97
98
99
100
# File 'lib/ruote/storage/fs_storage.rb', line 97

def ids(type)

  @cloche.ids(type)
end

#purge!Object

Purges the storage completely.



104
105
106
107
# File 'lib/ruote/storage/fs_storage.rb', line 104

def purge!

  FileUtils.rm_rf(@cloche.dir)
end

#purge_type!(type) ⇒ Object



114
115
116
117
# File 'lib/ruote/storage/fs_storage.rb', line 114

def purge_type!(type)

  @cloche.purge_type!(type)
end

#put(doc, opts = {}) ⇒ Object



71
72
73
74
# File 'lib/ruote/storage/fs_storage.rb', line 71

def put(doc, opts={})

  @cloche.put(doc.merge!('put_at' => Ruote.now_to_utc_s), opts)
end

#shutdownObject

Shuts this storage down.



133
134
135
136
# File 'lib/ruote/storage/fs_storage.rb', line 133

def shutdown

  # nothing to do
end