| 1 | package App::Workflow::Lint::Rule::MissingTimeout; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use Carp qw(croak carp); | ||
| 6 | |||
| 7 | # Inherit the DSL from the base rule class | ||
| 8 | use parent 'App::Workflow::Lint::Rule'; | ||
| 9 | |||
| 10 | #---------------------------------------------------------------------- | ||
| 11 | # Metadata | ||
| 12 | #---------------------------------------------------------------------- | ||
| 13 | |||
| 14 | sub id { 'missing-timeout' } | ||
| 15 | sub description { 'Jobs should define timeout-minutes' } | ||
| 16 | sub applies_to { 'job' } | ||
| 17 | sub level { 'warning' } | ||
| 18 | |||
| 19 | #---------------------------------------------------------------------- | ||
| 20 | # Rule logic | ||
| 21 | #---------------------------------------------------------------------- | ||
| 22 | |||
| 23 | sub check_job { | ||
| 24 | my ($self, $job, $ctx) = @_; | ||
| 25 | |||
| 26 | # If the job already has a timeout, nothing to report | ||
| 27 | return () if exists $job->{'timeout-minutes'}; | ||
| 28 | |||
| 29 | # Otherwise return a diagnostic | ||
| 30 | return $self->diag( | ||
| 31 | message => "Job '$ctx->{job_name}' is missing timeout-minutes", | ||
| 32 | path => "/jobs/$ctx->{job_name}", | ||
| 33 | file => $ctx->{file}, | ||
| 34 | fix => sub { | ||
| 35 | my ($wf) = @_; | ||
| 36 | $wf->{jobs}{$ctx->{job_name}}{'timeout-minutes'} = 10; | ||
| 37 | }, | ||
| 38 | ); | ||
| 39 | } | ||
| 40 | |||
| 41 | 1; | ||
| 42 |