Sha256: 6d0ec7b079789058bc901f7a46ccc3b8183012cb9aa1ee8e963a164b0307cf7f

Contents?: true

Size: 1.34 KB

Versions: 5

Compression:

Stored size: 1.34 KB

Contents

# OMF_VERSIONS = 6.0
#

def_property('name', 'garage', 'Name of garage')

garage = prop.name

defEvent :engine_created do |state|
  # state holds list of resources, and automatically updated once OMF inform messages received.
  state.find_all do |v|
    v[:type] == 'engine'
  end.size >= 1
end

defEvent :rpm_reached_4000 do |state|
  state.find_all do |v|
    v[:type] == 'engine' && v[:rpm] && v[:rpm] >= 4000
  end.size >= 1
end

# Define a group and add garages to it.
defGroup('garages', garage)

# :ALL_UP is a pre-defined event,
# triggered when all resources set to be part of groups are available and configured as members of the associated groups.
onEvent :ALL_UP do
  group('garages') do |g|
    g.create_resource('primary_engine', type: 'engine', sn: rand(1000))

    onEvent :engine_created do
      info ">>> Accelerating all engines"
      g.resources[type: 'engine'][name: 'primary_engine'].throttle = 50

      g.resources[type: 'engine'][name: 'primary_engine'].sn
      g.resources[type: 'engine'][name: 'primary_engine'].membership
    end

    onEvent :rpm_reached_4000 do
      info ">>> Engine RPM reached 4000"

      info ">>> Reduce engine throttle"
      g.resources[type: 'engine'].throttle = 0

      after 7.seconds do
        info ">>> Release engines"
        g.resources[type: 'engine'].release

        done!
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
omf_ec-6.0.2.pre.2 example/engine_oedl.rb
omf_ec-6.0.2.pre.1 example/engine_oedl.rb
omf_ec-6.0.1 example/engine_oedl.rb
omf_ec-6.0.0 example/engine_oedl.rb
omf_ec-6.0.0.pre.5 example/engine_oedl.rb