Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example/sample/pointer for code to run as a daemon and watch for etcd events #61

Open
foobargeez opened this issue Oct 11, 2018 · 3 comments

Comments

@foobargeez
Copy link
Contributor

Wondering if anyone has any code/sample/pointer for running a script as a daemon and watch for etcd events. Creating a watcher through Net::Etcd module works but then I also need a consumer to listen for events, as long as the watcher is alive, and report the changes back. Does that make sense? If so, would appreciate any help.

Thanks!

@hexfusion
Copy link
Owner

@foobargeez just did a quick scan and it seems like you could facilitate this with https://metacpan.org/pod/distribution/Proc-Daemon/lib/Proc/Daemon.pod

example usage
https://stackoverflow.com/questions/766397/how-can-i-run-a-perl-script-as-a-system-daemon-in-linux

I am sure you already know this but for others that may be interested. You can use the test as an example of how you can take action on the response from the callback. In my example I just pushed it to an array to count the records but you could do other fun things :).

lives_ok(
sub {
$watch = $etcd->watch(
{ key => 'foo' },
sub {
my ($result) = @_;
push @events, $result;
#print STDERR Dumper(undef, $result);
}
)->create;
},
"watch create"
);

Does this help at all?

@hexfusion
Copy link
Owner

@foobargeez just curious if you made any progress?

@hexfusion
Copy link
Owner

@foobargeez happy new year ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants