ETLp

 view release on metacpan or  search on metacpan

lib/ETLp/Audit/Job.pm  view on Meta::CPAN

package ETLp::Audit::Job;

use MooseX::Declare;

=head1 NAME

ETLp::Audit::Job - audit the execution of an ETLp job

=head1 DESCRIPTION

This class is used to manage the job's audit record

=cut

use DateTime;

class ETLp::Audit::Job with (ETLp::Role::Config, ETLp::Role::Schema,
                             ETLp::Role::Audit) {
    use Try::Tiny;
    use DateTime;
    use ETLp::Types;
    use ETLp::Audit::Item;
    
=head1 ATTRIBUTES

The attributes are populated during instantiation, and should not be provided
at object creation time

=head2 id

The Job identifier

=head2 session_id

The database session associated with the job

=head2 item

The currently executing item

=cut
    
    has 'session_id' => (is => 'rw', isa => 'Int', required => 0);   
    has 'id' => (is => 'rw', isa => 'Int', required => 0);
    has 'name' => (is => 'ro', isa => 'Str', required => 1);
    has 'section' => (is => 'ro', isa => 'Str', required => 1);
    has 'config'  => (is => 'ro', isa => 'HashRef', required => 1);
    
=head1 METHODS

=head2 create_item

Create an audit item

=head3 parameters (Hash)

    * Str name: Name of the item
    * Str type: The item type
    * Str phase: The item phase
    
=head3 returns

    * An ETLp::Audit::Item
    
=cut
    
    method create_item(Str :$name, Str :$type, Str :$phase) {    
        my $item = ETLp::Audit::Item->new(
            name       => $name,
            type       => $type,
            phase      => $phase,
            job        => $self,
            config     => $self->config
        );
        $self->{item} = $item;
        return $item;
    }
    
    method item {
        return $self->{item};
    }
    
    method _start_audit {
        my $now = $self->now;
        try {
            $self->schema->txn_do(
                sub {
                    my $config = $self->EtlpConfiguration->find_or_create(
                        {
                            config_name => $self->name,
                            date_created => $now,
                            date_updated => $now
                        },                                                                                               
                        {key => 'etlp_configuration_u1'}
                    );
                    
                    my $section = $self->EtlpSection->find_or_create(
                        {
                            config_id    => $config->config_id,
                            section_name => $self->section,
                            date_created => $now,
                            date_updated => $now
                        },
                        {key => 'etlp_section_u1'}
                    );
                    
                    my $job = $self->EtlpJob->create(



( run in 1.915 second using v1.01-cache-2.11-cpan-5a3173703d6 )