« blib/lib/Langertha/Skeid/Protocol/Refusal.pm
↑ Summary
blib/lib/Langertha/Skeid/Proxy/RelayContent.pm »
| 1 | package Langertha::Skeid::CapacityProbe::Custom; | ||||||||||
| 2 | 5 | our $VERSION = '0.003'; | |||||||||
| 3 | # ABSTRACT: Capacity probe backed by a caller-supplied callback | ||||||||||
| 4 | 5 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 5 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 5 | extends 'Langertha::Skeid::CapacityProbe'; | |||||||||
| 9 | |||||||||||
| 10 | |||||||||||
| 11 | |||||||||||
| 12 | has code => ( | ||||||||||
| 13 | is => 'ro', | ||||||||||
| 14 | required => 1, | ||||||||||
| 15 | 17 | ▶ | isa => sub { croak 'custom capacity probe needs a coderef' unless ref($_[0]) eq 'CODE' }, | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||
| 16 | 5 | ); | |||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | 15 | ▶ | sub poll { | ||||||||
|
Subroutine
poll: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 20 | 15 | my ($self) = @_; | |||||||||
| 21 | 15 | return $self->code->($self); | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | 5 | 1; | |||||||||
| 26 | |||||||||||
| 27 | __END__ | ||||||||||
| 28 | |||||||||||
| 29 | =pod | ||||||||||
| 30 | |||||||||||
| 31 | =encoding UTF-8 | ||||||||||
| 32 | |||||||||||
| 33 | =head1 NAME | ||||||||||
| 34 | |||||||||||
| 35 | Langertha::Skeid::CapacityProbe::Custom - Capacity probe backed by a caller-supplied callback | ||||||||||
| 36 | |||||||||||
| 37 | =head1 VERSION | ||||||||||
| 38 | |||||||||||
| 39 | version 0.003 | ||||||||||
| 40 | |||||||||||
| 41 | =head1 SYNOPSIS | ||||||||||
| 42 | |||||||||||
| 43 | $skeid->add_node( | ||||||||||
| 44 | id => 'weird-1', url => 'http://weird-1/v1', model => 'm', | ||||||||||
| 45 | capacity => { | ||||||||||
| 46 | probe => 'custom', | ||||||||||
| 47 | interval_ms => 1000, | ||||||||||
| 48 | code => sub { | ||||||||||
| 49 | my ($probe) = @_; | ||||||||||
| 50 | my $depth = ask_the_thing(); # must not block | ||||||||||
| 51 | $probe->skeid->set_capacity_reading($probe->node_id, | ||||||||||
| 52 | source => 'custom', used => $depth, limit => 16); | ||||||||||
| 53 | }, | ||||||||||
| 54 | }, | ||||||||||
| 55 | ); | ||||||||||
| 56 | |||||||||||
| 57 | =head1 DESCRIPTION | ||||||||||
| 58 | |||||||||||
| 59 | Skeid fronts whatever an operator happens to run, so "any way of finding out how busy a node | ||||||||||
| 60 | is" has to be part of the contract rather than something bolted on when the built-ins run out | ||||||||||
| 61 | (ADR 0009). The built-in probes are conveniences for the engines we know about. | ||||||||||
| 62 | |||||||||||
| 63 | The callback gets the probe and reports through the same methods as any other probe: | ||||||||||
| 64 | C<set_capacity_reading> when it knows, C<forget_capacity> when it does not. It runs on a timer, | ||||||||||
| 65 | never on the request path, so it must not block — the whole process waits on it. | ||||||||||
| 66 | |||||||||||
| 67 | =head2 code | ||||||||||
| 68 | |||||||||||
| 69 | The callback, called with the probe as its only argument. | ||||||||||
| 70 | |||||||||||
| 71 | =head2 poll | ||||||||||
| 72 | |||||||||||
| 73 | Calls L</code> with the probe. A callback that dies makes the probe forget its reading, as any | ||||||||||
| 74 | failed poll does. | ||||||||||
| 75 | |||||||||||
| 76 | =head1 SEE ALSO | ||||||||||
| 77 | |||||||||||
| 78 | L<Langertha::Skeid::CapacityProbe> | ||||||||||
| 79 | |||||||||||
| 80 | =head1 SUPPORT | ||||||||||
| 81 | |||||||||||
| 82 | =head2 Issues | ||||||||||
| 83 | |||||||||||
| 84 | Please report bugs and feature requests on GitHub at | ||||||||||
| 85 | L<https://github.com/Getty/langertha-skeid/issues>. | ||||||||||
| 86 | |||||||||||
| 87 | =head2 IRC | ||||||||||
| 88 | |||||||||||
| 89 | Join C<#langertha> on C<irc.perl.org> or message Getty directly. | ||||||||||
| 90 | |||||||||||
| 91 | =head1 CONTRIBUTING | ||||||||||
| 92 | |||||||||||
| 93 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||
| 94 | |||||||||||
| 95 | =head1 AUTHOR | ||||||||||
| 96 | |||||||||||
| 97 | Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/> | ||||||||||
| 98 | |||||||||||
| 99 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 100 | |||||||||||
| 101 | This software is copyright (c) 2026 by Torsten Raudssus. | ||||||||||
| 102 | |||||||||||
| 103 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 104 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 105 | |||||||||||
| 106 | =cut | ||||||||||