Sha256: edbbac4a19410e3237ba123173c27708edfa9edad74de680f138f3344bb2d997
Contents?: true
Size: 1.17 KB
Versions: 1
Compression:
Stored size: 1.17 KB
Contents
# frozen_string_literal: true require_relative 'time_bomb/bomb' module Ragent module Plugin class TimeBomb include Ragent::Plugin plugin_name 'time_bomb' commands :tick, :list, :disarm def configure(*_args) @next_time_bomb_id = 1 @time_bombs = {} subscribe('time-bomb-boom', :boom_callback) end def command_disarm(options) bomb_name = "time_bomb_#{options['bomb']}" bomb = agents(bomb_name) if bomb bomb.terminate @time_bombs.delete(bomb_name) "terminated #{bomb_name}" else "no such bomb #{bomb_name}" end end def command_list(_options) @time_bombs.keys.join("\n") end def command_tick(_options) # how to track the bombs to disarm them? as = "time_bomb_#{@next_time_bomb_id}" @time_bombs[as] = true @next_time_bomb_id += 1 agent(type: TimeBomb::Bomb, as: as) "starting #{as}" end def boom_callback(_topic, params) debug "boom: #{params.inspect}" end end end end Ragent.ragent.plugins.register('time_bomb', Ragent::Plugin::TimeBomb)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ragent-0.0.4 | examples/lib/ragent/plugin/time_bomb.rb |