The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Proc::tored::Role::Running - add running state and signal handling to services

VERSION

version 0.05

SYNOPSIS

  package Some::Thing;
  use Moo;

  with 'Proc::tored::Running';

  sub run {
    my $self = shift;

    $self->start;

    while ($self->is_running) {
      do_stuff(...);
    }
  }

DESCRIPTION

Classes consuming this role are provided with controls to "start" and "stop" voluntarily, along with a SIGTERM handler that is active while the class "is_running". If a SIGTERM is received via another process (e.g., by calling "stop_running_process" in Proc::tored::Manager), the class will voluntarily "stop" itself.

ATTRIBUTES

run_guard

A Guard used to ensure signal handlers are restored when the object is destroyed.

METHODS

is_running

Returns true while the service is running in the current process.

start

Flags the current process as running. While running, handlers for SIGTERM, SIGINT, SIGPIPE, and SIGHUP are installed. After calling this method, "is_running" will return true.

stop

Flags the current process as not running and restores any previously configured signal handlers. Once this method has been called, "is_running" will return false.

AUTHOR

Jeff Ober <jeffober@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Jeff Ober.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.