| 1 | package Daje::Sentinel::Api; | ||
| 2 | use Mojo::Base -base; | ||
| 3 | |||
| 4 | use Daje::Utils::Factory::Collection qw{load_collection}; | ||
| 5 | use POSIX qw(strftime); | ||
| 6 | use Try::Tiny; | ||
| 7 | |||
| 8 | our $VERSION = '0.13'; | ||
| 9 | |||
| 10 | has 'mango'; | ||
| 11 | # Capture message and insert it into the collection | ||
| 12 | # my $oid = $self->capture_message($source, $method, $message) | ||
| 13 | # $source, $method are used for filtering and message is the actual error | ||
| 14 | # $oid is the returned _id from MungoDB | ||
| 15 | # | ||
| 16 | sub capture_message{ # $oid ($source, $method, $message) | ||
| 17 | my ($self, $source, $method, $message) = @_; | ||
| 18 | |||
| 19 | my $classname = load_collection("Sentinel"); | ||
| 20 | |||
| 21 | my $oid = try { | ||
| 22 | return $classname->new( | ||
| 23 | mango => $self->mango, | ||
| 24 | query => { | ||
| 25 | source => $source, | ||
| 26 | method => $method, | ||
| 27 | message => $message, | ||
| 28 | doc_updated => strftime ("%Y-%m-%d %H:%M:%S", localtime), | ||
| 29 | } | ||
| 30 | )->insert(); | ||
| 31 | } catch { | ||
| 32 | say $_; | ||
| 33 | return $_; | ||
| 34 | }; | ||
| 35 | |||
| 36 | return $oid; | ||
| 37 | } | ||
| 38 | |||
| 39 | 1; | ||
| 40 | |||
| 41 | |||
| 42 | |||
| 43 | |||
| 44 | |||
| 45 | #################### pod generated by Pod::Autopod - keep this line to make pod updates possible #################### | ||
| 46 | |||
| 47 | =head1 NAME | ||
| 48 | |||
| 49 | Daje::Sentinel::Api | ||
| 50 | |||
| 51 | |||
| 52 | =head1 DESCRIPTION | ||
| 53 | |||
| 54 | Capture message and insert it into the collection | ||
| 55 | my $oid = $self->capture_message($source, $method, $message) | ||
| 56 | $source, $method are used for filtering and message is the actual error | ||
| 57 | $oid is the returned _id from MungoDB | ||
| 58 | |||
| 59 | |||
| 60 | |||
| 61 | =head1 REQUIRES | ||
| 62 | |||
| 63 | L<Try::Tiny> | ||
| 64 | |||
| 65 | L<POSIX> | ||
| 66 | |||
| 67 | L<Daje::Utils::Factory::Collection> | ||
| 68 | |||
| 69 | L<Mojo::Base> | ||
| 70 | |||
| 71 | |||
| 72 | =head1 METHODS | ||
| 73 | |||
| 74 | =head2 capture_message | ||
| 75 | |||
| 76 | my $oid = capture_message($source, $method, $message); | ||
| 77 | |||
| 78 | has 'mango'; | ||
| 79 | Capture message and insert it into the collection | ||
| 80 | my $oid = $self->capture_message($source, $method, $message) | ||
| 81 | $source, $method are used for filtering and message is the actual error | ||
| 82 | $oid is the returned _id from MungoDB | ||
| 83 | |||
| 84 | |||
| 85 | |||
| 86 | |||
| 87 | =cut | ||
| 88 |