Sponsoring The Perl Toolchain Summit 2025: Help make this important event another success Learn more

NAME

App::MonM::Notifier::Store - monotifier store class

VERSION

Version 1.02

SYNOPSIS

my $store = App::MonM::Notifier::Store->new(
dsn => "DBI:mysql:database=monotifier;host=mysql.example.com",
user => "username",
password => "password",
set => [
"RaiseError 0",
"PrintError 0",
"mysql_enable_utf8 1",
],
expires => 3600*24*7,
maxtime => 300,
);
die($store->error) if $store->error;

DESCRIPTION

DBI interface for monotifier store. This module provides store methods

new

my $store = App::MonM::Notifier::Store->new(
dsn => "DBI:mysql:database=monotifier;host=mysql.example.com",
user => "username",
password => "password",
set => [
"RaiseError 0",
"PrintError 0",
"mysql_enable_utf8 1",
],
expires => 3600*24*7,
maxtime => 300,
);

Creates DBI object

expires
Time in seconds of life of database record
maxtime
Max time in seconds to sending one message

cleanup

my $st = $store->cleanup;

Removes permanently queue entities based on how old they are

dequeue

my $st = $store->dequeue(
id => 1,
);

Dequeues the element by setting success status (STATUS_SENT)

delById

$store->delById($id) or die($store->error);

Delete record by id

dsn

my $dsn = $store->dsn;

Returns DSN string of current database connection

enqueue

$store->enqueue(
to => $user,
channel => $ch_name,
subject => $subject,
message => $message,
attributes => $ch, # Channel attributes
) or die($store->error);

Adds a new element at the end of the current queue and returns queue element ID

error

my $error = $store->error;

Returns error message

my $error = $store->error( "Error message" );

Sets error message if argument is provided.

getById

my %data = $store->getById($id);

Returns data from database by id

getAll

my @table = $store->getAll();
my @table_100 = $store->getAll(100);

Returns data from database with limit supporting

is_sqlite

print $store->is_sqlite ? "Is SQLite" : "Is not SQLite"

Returns true if type of current database is SQLite

ping

$store->ping ? 'OK' : 'Database session is expired';

Checks the connection to database

requeue

my $st = $store->requeue(
id => 1,
code => 2,
error => "My Error",
);

Requeue entities that have been retrieved for processing early; sets status to STATUS_FAIL

retrieve

my $entity = $store->retrieve(STATUS_FAIL);

Retrieves the next entity from the queue and returns it as hashref or undef if no entity

serializer

my $serializer = $store->serializer;

Returns serializer object

purge

$store->purge or die($store->error);

Delete all records

DDL

CREATE TABLE IF NOT EXISTS monotifier (
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
`to` CHAR(255), -- Recipient name
`channel` CHAR(255), -- Recipient channel
`subject` TEXT, -- Message subject
`message` TEXT, -- Message content (BASE64)
`attributes` TEXT, -- Message attributes (JSON)
`published` BIGINT(20), -- The publication time (unixtime)
`scheduled` BIGINT(20), -- The scheduled time (unixtime)
`expired` BIGINT(20), -- The expiration time (unixtime)
`sent` BIGINT(20), -- The send time
`attempt` INTEGER DEFAULT 0, -- Count of failed attempts
`status` CHAR(32), -- Status of transaction
`errcode` INT(11), -- Error code
`errmsg` TEXT -- Error message
)

ERRORCODES

0 -- No errors found
1 -- Error of the notifier level (notify method)
2 -- Error of the notifier level (remind method)
255 -- Error of the cleanup level

SEE ALSO

CTK::DBI, App::MonM

AUTHOR

Serż Minus (Sergey Lepenkov) https://www.serzik.com <abalama@cpan.org>

COPYRIGHT

Copyright (C) 1998-2022 D&D Corporation. All Rights Reserved

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See LICENSE file and https://dev.perl.org/licenses/