initial broken implementation of the runner
This commit is contained in:
5
Build.PL
5
Build.PL
@@ -13,6 +13,9 @@ Module::Build->new(
|
||||
build_requires => {
|
||||
},
|
||||
requires => {
|
||||
'aliased' => '0',
|
||||
'namespace::clean' => '0.24',
|
||||
'version' => '0.9902',
|
||||
'Algorithm::Cron' => '0.07',
|
||||
'AnyEvent' => '7.05',
|
||||
'AnyEvent::DNS::EtcHosts' => '0',
|
||||
@@ -71,8 +74,6 @@ Module::Build->new(
|
||||
'URL::Encode' => '0.01',
|
||||
'YAML' => '0.84',
|
||||
'YAML::XS' => '0.41',
|
||||
'namespace::clean' => '0.24',
|
||||
'version' => '0.9902',
|
||||
},
|
||||
recommends => {
|
||||
'Graph' => '0',
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package App::Netdisco::Backend::Runner;
|
||||
|
||||
use Dancer ':moose :syntax';
|
||||
use App::Netdisco::Worker::Status;
|
||||
use Dancer::Factory::Hook;
|
||||
use aliased 'App::Netdisco::Worker::Status';
|
||||
|
||||
use Try::Tiny;
|
||||
use Role::Tiny;
|
||||
@@ -9,7 +10,44 @@ use namespace::clean;
|
||||
|
||||
# mixin code to run workers loaded via plugins
|
||||
sub run {
|
||||
return App::Netdisco::Worker::Status->new({done => true, message => 'ok'});
|
||||
my ($self, $job) = @_;
|
||||
die 'bad job to run()' unless ref $job eq 'App::Netdisco::Backend::Job';
|
||||
|
||||
my $action = $job->action;
|
||||
my @phase_hooks = @{ (setting('_nd2worker_hooks') || []) };
|
||||
|
||||
# run 00init primary
|
||||
my $status = _run_first("nd2worker_${action}_00init_primary", $job);
|
||||
return $status if $status->not_ok;
|
||||
|
||||
# run each 00init worker
|
||||
_run_all("nd2worker_${action}_00init", $job);
|
||||
|
||||
# run primary
|
||||
_run_first($_.'_primary', $job)
|
||||
for (grep { m/^nd2worker_${action}_/ } @phase_hooks);
|
||||
|
||||
# run each worker
|
||||
_run_all($_, $job)
|
||||
for (grep { m/^nd2worker_${action}_/ } @phase_hooks);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
sub _run_first {
|
||||
my $hook = shift or return Status->error('missing hook param');
|
||||
my $job = shift or return Status->error('missing job param');
|
||||
|
||||
my $store = Dancer::Factory::Hook->instance();
|
||||
$store->hook_is_registered($hook)
|
||||
or return Status->error("no such hook: $hook");
|
||||
|
||||
foreach my $worker (@{ $store->get_hooks_for($hook) }) {
|
||||
my $status = $worker->($job);
|
||||
return $status if $status->ok;
|
||||
}
|
||||
|
||||
return Status->error('no worker was successful');
|
||||
}
|
||||
|
||||
true;
|
||||
|
||||
@@ -67,15 +67,16 @@ register 'register_worker' => sub {
|
||||
|
||||
my $primary = ($workerconf->{primary} ? '_primary' : '');
|
||||
my $hook = 'nd2worker_'. $action .'_'. $phase . $primary;
|
||||
my $store = Dancer::Factory::Hook->instance();
|
||||
|
||||
if (not Dancer::Factory::Hook->instance->hook_is_registered($hook)) {
|
||||
Dancer::Factory::Hook->instance->install_hooks($hook);
|
||||
if (not $store->hook_is_registered($hook)) {
|
||||
$store->install_hooks($hook);
|
||||
# track just the basic phase names which are used
|
||||
push @{ setting('_nd2worker_hooks') }, $hook
|
||||
if $phase ne '00init' and 0 == length($primary);
|
||||
}
|
||||
|
||||
Dancer::Factory::Hook->instance->register_hook($hook, $worker);
|
||||
$store->register_hook($hook, $worker);
|
||||
};
|
||||
|
||||
register_plugin;
|
||||
|
||||
@@ -25,6 +25,16 @@ has 'log' => (
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 done, error, defer
|
||||
|
||||
Shorthand for new() with setting param, accepts log as arg.
|
||||
|
||||
=cut
|
||||
|
||||
sub done { return (shift)->new({done => 1, log => shift}) }
|
||||
sub error { return (shift)->new({error => 1, log => shift}) }
|
||||
sub defer { return (shift)->new({defer => 1, log => shift}) }
|
||||
|
||||
=head2 ok
|
||||
|
||||
Returns true if C<done> is true and C<error> and C<defer> have not been set.
|
||||
|
||||
Reference in New Issue
Block a user