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, #dump, #empty?, #expression_wfids, #find_expressions, #find_root_expression, #find_root_expressions, #get_configuration, #get_engine_variable, #get_msgs, #get_schedules, #get_trackers, #put_engine_variable, #put_msg, #put_schedule, #remove_process, #replace_engine_configuration, #reserve, #worker

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.


51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ruote/storage/fs_storage.rb', line 51

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'])

  replace_engine_configuration(options)
end

Instance Method Details

#add_type(type) ⇒ Object

No need for that here (FsStorage can add types on the fly).


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

def add_type(type)
end

#delete(doc) ⇒ Object


85
86
87
88
# File 'lib/ruote/storage/fs_storage.rb', line 85

def delete(doc)

  @cloche.delete(doc)
end

#dirObject


66
67
68
69
# File 'lib/ruote/storage/fs_storage.rb', line 66

def dir

  @cloche.dir
end

#get(type, key) ⇒ Object


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

def get(type, key)

  @cloche.get(type, key)
end

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


90
91
92
93
94
95
96
97
98
99
# File 'lib/ruote/storage/fs_storage.rb', line 90

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

  keys = key ? Array(key) : nil

  keys = keys.map { |k|
    type == 'schedules' ? /!#{k}-\d+$/ : "!#{k}"
  } if keys && keys.first.is_a?(String)

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

#ids(type) ⇒ Object


101
102
103
104
# File 'lib/ruote/storage/fs_storage.rb', line 101

def ids(type)

  @cloche.ids(type)
end

#purge!Object

Purges the storage completely.


108
109
110
111
# File 'lib/ruote/storage/fs_storage.rb', line 108

def purge!

  FileUtils.rm_rf(@cloche.dir)
end

#purge_type!(type) ⇒ Object


118
119
120
121
# File 'lib/ruote/storage/fs_storage.rb', line 118

def purge_type!(type)

  @cloche.purge_type!(type)
end

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


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

def put(doc, opts={})

  doc = doc.send(
    opts[:update_rev] ? 'merge!' : 'merge',
    'put_at' => Ruote.now_to_utc_s)

  @cloche.put(doc, opts)
end

#shutdownObject

Shuts this storage down.


125
126
127
128
# File 'lib/ruote/storage/fs_storage.rb', line 125

def shutdown

  # nothing to do
end