Class/Module Index [+]

Quicksearch

Ruote::StorageBase

Base methods for storage implementations.

Public Instance Methods

context() click to toggle source
# File lib/ruote/storage/base.rb, line 35
def context

  @context ||= Ruote::Context.new(self)
end
context=(c) click to toggle source
# File lib/ruote/storage/base.rb, line 40
def context= (c)

  @context = c
end
copy_to(target, opts={}) click to toggle source

Copies the content of this storage into a target storage.

Of course, the target storage may be a different implementation.

# File lib/ruote/storage/base.rb, line 189
def copy_to (target, opts={})

  counter = 0

  ]
    configurations errors expressions msgs schedules variables workitems
  ].each do |type|

    ids(type).each do |id|

      item = get(type, id)

      item.delete('_rev')
      target.put(item)

      counter += 1
      puts("  #{type}/#{item['_id']}") if opts[:verbose]
    end
  end

  counter
end
delete_schedule(schedule_id) click to toggle source
# File lib/ruote/storage/base.rb, line 158
def delete_schedule (schedule_id)

  s = get('schedules', schedule_id)
  delete(s) if s
end
empty?(type) click to toggle source
# File lib/ruote/storage/base.rb, line 96
def empty? (type)

  (get_many(type) == [])
end
find_root_expression(wfid) click to toggle source
# File lib/ruote/storage/base.rb, line 105
def find_root_expression (wfid)

  get_many('expressions', /!#{wfid}$/).sort { |a, b|
    a['fei']['expid'] <=> b['fei']['expid']
  }.select { |e|
    e['parent_id'].nil?
  }.first
end
get_configuration(key) click to toggle source
# File lib/ruote/storage/base.rb, line 57
def get_configuration (key)

  get('configurations', key)
end
get_engine_variable(k) click to toggle source
# File lib/ruote/storage/base.rb, line 168
def get_engine_variable (k)

  get_engine_variables['variables'][k]
end
get_msgs() click to toggle source

def get_local_msgs

p @local_msgs
if @local_msgs
  r = @local_msgs
  @local_msgs = nil
  r
else
  []
end

end

# File lib/ruote/storage/base.rb, line 87
def get_msgs

  get_many(
    'msgs', nil, :limit => 300
  ).sort { |a, b|
    a['put_at'] <=> b['put_at']
  }
end
get_schedules(delta, now) click to toggle source
# File lib/ruote/storage/base.rb, line 128
def get_schedules (delta, now)

  # TODO : bring that 'optimization' back in,
  #        maybe every minute, if min != last_min ...

  #if delta < 1.0
  #  at = now.strftime('%Y%m%d%H%M%S')
  #  get_many('schedules', /-#{at}$/)
  #elsif delta < 60.0
  #  at = now.strftime('%Y%m%d%H%M')
  #  scheds = get_many('schedules', /-#{at}\d\d$/)
  #  filter_schedules(scheds, now)
  #else # load all the schedules

  scheds = get_many('schedules')
  filter_schedules(scheds, now)

  #end
end
get_trackers() click to toggle source
# File lib/ruote/storage/base.rb, line 118
def get_trackers

  get('variables', 'trackers') ||
    { '_id' => 'trackers', 'type' => 'variables', 'trackers' => {} }
end
put_engine_variable(k, v) click to toggle source
# File lib/ruote/storage/base.rb, line 173
def put_engine_variable (k, v)

  vars = get_engine_variables
  vars['variables'][k] = v

  put_engine_variable(k, v) unless put(vars).nil?
end
put_msg(action, options) click to toggle source
# File lib/ruote/storage/base.rb, line 66
def put_msg (action, options)

  msg = prepare_msg_doc(action, options)

  put(msg)

  #put(msg, :update_rev => true)
  #(@local_msgs ||= []) << Ruote.fulldup(msg)
end
put_schedule(flavour, owner_fei, s, msg) click to toggle source
# File lib/ruote/storage/base.rb, line 148
def put_schedule (flavour, owner_fei, s, msg)

  if doc = prepare_schedule_doc(flavour, owner_fei, s, msg)
    put(doc)
    return doc['_id']
  end

  nil
end
reserve(doc) click to toggle source

Attempts to delete a document, returns true if the deletion succeeded. This is used with msgs to reserve work on them.

# File lib/ruote/storage/base.rb, line 48
def reserve (doc)

  delete(doc).nil?
end

Protected Instance Methods

filter_schedules(scheds, now) click to toggle source

Returns all the ats whose due date arrived (now or earlier)

# File lib/ruote/storage/base.rb, line 277
def filter_schedules (scheds, now)

  now = Ruote.time_to_utc_s(now)

  scheds.select { |sched| sched['at'] <= now }
end
get_engine_variables() click to toggle source
# File lib/ruote/storage/base.rb, line 269
def get_engine_variables

  get('variables', 'variables') || {
    'type' => 'variables', '_id' => 'variables', 'variables' => {} }
end
prepare_msg_doc(action, options) click to toggle source

Used by put_msg

# File lib/ruote/storage/base.rb, line 216
def prepare_msg_doc (action, options)

  # merge! is way faster than merge (no object creation probably)

  @counter ||= 0

  t = Time.now.utc
  ts = "#{t.strftime('%Y-%m-%d')}!#{t.to_i}.#{'%06d' % t.usec}"
  _id = "#{$$}!#{Thread.current.object_id}!#{ts}!#{'%03d' % @counter}"

  @counter = (@counter + 1) % 1000
    # some platforms (windows) have shallow usecs, so adding that counter...

  msg = options.merge!('type' => 'msgs', '_id' => _id, 'action' => action)

  msg.delete('_rev')
    # in case of message replay

  msg
end
prepare_schedule_doc(flavour, owner_fei, s, msg) click to toggle source

Used by put_schedule

# File lib/ruote/storage/base.rb, line 239
def prepare_schedule_doc (flavour, owner_fei, s, msg)

  at = if s.is_a?(Time) # at or every
    s
  elsif Ruote.is_cron_string(s) # cron
    Rufus::CronLine.new(s).next_time(Time.now + 1)
  else # at or every
    Ruote.s_to_at(s)
  end
  at = at.utc

  if at <= Time.now.utc && flavour == 'at'
    put_msg(msg.delete('action'), msg)
    return false
  end

  sat = at.strftime('%Y%m%d%H%M%S')
  i = "#{flavour}-#{Ruote.to_storage_id(owner_fei)}-#{sat}"

  {
    '_id' => i,
    'type' => 'schedules',
    'flavour' => flavour,
    'original' => s,
    'at' => Ruote.time_to_utc_s(at),
    'owner' => owner_fei,
    'msg' => msg
  }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.