fix(tools): enable anvil-access-module to emit events

main
Tsu-ba-me 1 year ago
parent e670e0f94c
commit b7629e4c2b
  1. 43
      tools/anvil-access-module

@ -474,19 +474,19 @@ sub pstderr
$anvil->Get->switches; $anvil->Get->switches;
$anvil->Database->connect;
$anvil->Log->entry({ source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132" });
if (not $anvil->data->{sys}{database}{connections})
{
# No databases, exit.
$anvil->Log->entry({ source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0003" });
$anvil->nice_exit({ exit_code => 1 });
}
my $data_hash = $anvil->data->{switches}{'data'}; my $data_hash = $anvil->data->{switches}{'data'};
my $switch_debug = $anvil->data->{switches}{'debug'} // 3; my $switch_debug = $anvil->data->{switches}{'debug'} // 3;
my $db_access_mode = $anvil->data->{switches}{'mode'} // ""; my $db_access_mode = $anvil->data->{switches}{'mode'} // "";
my $db_uuid = $anvil->data->{switches}{'uuid'}; my $db_uuid = $anvil->data->{switches}{'uuid'};
#
# Events in this context are simply printing the event name before
# and/or after operations. The output should enable other programs to
# parse and activate additional logic as necessary.
#
# Event names should be present-tense before an operation, and
# past-tense after.
#
my $emit_events = $anvil->data->{switches}{'emit-events'};
my $pre_data = $anvil->data->{switches}{'predata'}; my $pre_data = $anvil->data->{switches}{'predata'};
my $script_file = $anvil->data->{switches}{'script'} // "-"; my $script_file = $anvil->data->{switches}{'script'} // "-";
my $sql_query = $anvil->data->{switches}{'query'}; my $sql_query = $anvil->data->{switches}{'query'};
@ -494,6 +494,19 @@ my $sub_module_name = $anvil->data->{switches}{'sub-module'} // "Database";
my $sub_name = $anvil->data->{switches}{'sub'} // ""; my $sub_name = $anvil->data->{switches}{'sub'} // "";
my $sub_params = $anvil->data->{switches}{'sub-params'} // "{}"; my $sub_params = $anvil->data->{switches}{'sub-params'} // "{}";
emit("initialized");
$anvil->Database->connect;
$anvil->Log->entry({ source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132" });
if (not $anvil->data->{sys}{database}{connections})
{
# No databases, exit.
$anvil->Log->entry({ source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0003" });
$anvil->nice_exit({ exit_code => 1 });
}
emit("connected");
if ($sql_query) if ($sql_query)
{ {
my $results = db_access({ db_uuid => $db_uuid, sql_query => $sql_query, db_access_mode => $db_access_mode }); my $results = db_access({ db_uuid => $db_uuid, sql_query => $sql_query, db_access_mode => $db_access_mode });
@ -612,4 +625,16 @@ else
}; };
} }
emit("exit");
$anvil->nice_exit({ exit_code => 0 }); $anvil->nice_exit({ exit_code => 0 });
##################################################
# Functions
##################################################
# TODO: need to move all subroutines down here.
sub emit
{
pstdout("event=".$_[0]) if ($emit_events);
}

Loading…
Cancel
Save