Skip to content

Commit 650871b

Browse files
authored
Merge pull request #602 from kquick/pathinput_freq
Allow PathInput to take an optional frequency parameter.
2 parents b2030cd + 44780c7 commit 650871b

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/lib/Hydra/Plugin/PathInput.pm

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,31 @@ sub supportedInputTypes {
1212
$inputTypes->{'path'} = 'Local path or URL';
1313
}
1414

15+
sub _parseValue {
16+
# The input is a local path or URL, optionally followed by a
17+
# time period specified in seconds.
18+
my ($config, $value) = @_;
19+
my @parts = split ' ', $value;
20+
(my $uri, my $freq) = @parts;
21+
# By default don't check a path more often than every 30 seconds,
22+
# but the second path argument can change that value or the global
23+
# path_input_cache_validity_seconds configuration, in that order.
24+
my $timeout = defined $freq ? $freq : ($config->{path_input_cache_validity_seconds} // 30);
25+
26+
return ($uri, $timeout);
27+
}
28+
1529
sub fetchInput {
1630
my ($self, $type, $name, $value) = @_;
1731

1832
return undef if $type ne "path";
1933

20-
my $uri = $value;
34+
my ($uri, $timeout) = _parseValue($self->{config}, $value);
2135

2236
my $timestamp = time;
2337
my $sha256;
2438
my $storePath;
2539

26-
my $timeout = $self->{config}->{path_input_cache_validity_seconds} // 30;
27-
2840
# Some simple caching: don't check a path more than once every N seconds.
2941
(my $cachedInput) = $self->{db}->resultset('CachedPathInputs')->search(
3042
{srcpath => $uri, lastseen => {">", $timestamp - $timeout}},

0 commit comments

Comments
 (0)