Example #1
0
    oh.__annotations__ = {}  # needed to please Plugin._coerce_arguments()
    plugin.add_hook(str(ht), oh)


def on_notification(notification_type_name, plugin, *args, **kwargs):
    if len(args) != 0:
        plugin.log("got unexpected args: {}".format(args), level="warn")
    reactor.callFromThread(publisher.publish_notification,
                           notification_type_name, *args, **kwargs)


for nt in NOTIFICATION_TYPES:
    # subscribe to all notifications
    on = functools.partial(on_notification, str(nt))
    on.__annotations__ = {}  # needed to please Plugin._coerce_arguments()
    plugin.add_subscription(str(nt), on)

DEFAULT_HIGH_WATER_MARK = 1000

for t in ALL_TYPES:
    # zmq socket binding option
    endpoint_opt = t.endpoint_option()
    endpoint_desc = "Enable publish {} info to ZMQ socket endpoint".format(t)
    plugin.add_option(endpoint_opt, None, endpoint_desc, opt_type='string')
    # high water mark option
    hwm_opt = t.hwm_option()
    hwm_desc = ("Set publish {} info message high water mark "
                "(default: {})".format(t, DEFAULT_HIGH_WATER_MARK))
    plugin.add_option(hwm_opt,
                      DEFAULT_HIGH_WATER_MARK,
                      hwm_desc,
        f.write(json.dumps(dict(nodes=with_degree)))
    return with_degree


@plugin.init()
def init(configuration, options, plugin):
    plugin.probe_interval = int(options['probe-interval'])
    plugin.probe_exclusion_duration = int(options['probe-exclusion-duration'])

    db_filename = 'sqlite:///' + os.path.join(configuration['lightning-dir'],
                                              'probe_all.db')

    engine = create_engine(db_filename, echo=True)
    Base.metadata.create_all(engine)
    plugin.Session = sessionmaker()
    plugin.Session.configure(bind=engine)
    t.daemon = True
    t.start()

    # Probes that are still pending and need to be checked against.
    plugin.pending_probes = []


plugin.add_option('probe-interval', '60',
                  'How many seconds should we wait between probes?')
plugin.add_option(
    'probe-exclusion-duration', '1800',
    'How many seconds should temporarily failed channels be excluded?')
plugin.add_subscription('disconnect', on_disconnect)
plugin.run()