NAME
Helios::App::MP3IndexerService - Helios service to index MP3s to a database table
SYNOPSIS
# start the service daemon
helios.pl Helios::App::MP3IndexerService
# submit jobs using the included cmd line utility
locate .mp3|mp3submit4index.pl
DESCRIPTION
This is a sample application to demonstrate some of the features of the Helios distributed job processing system and how to write services for it.
DATABASE SCHEMA
The sql/schema.sql file contains the SQL to create the MP3_INDEX_TB table that MP3IndexerService will write all of its data to. Edit it appropriately for your system and issue a command like the following:
mysql -D indexer_db -u indexer_user -p < schema.sql
CONFIG PARAMETERS
The config.sh file contains the commands necessary to configure Helios::App::MP3IndexerService in the Helios collective database. Edit the --value parameters to provide the database info for the indexer database (created above) and then run config.sh to complete Helios::App::MP3IndexerService configuration.
SERVICE START
Once that is done, you should be able to start the service with helios.pl:
helios.pl Helios::App::MP3IndexerService
and then submit jobs to the service using the included mp3submit4index.pl program:
find / -name "*\.mp3" -print | mp3submit4index.pl
Happy MP3 indexing!
RUN() METHOD
As always in Helios applications, the run() method is the main subroutine in the application. It receives a job to process in the form of a Helios::Job object, it calls the subroutines or methods necessary to do the job processing, then it marks the job as successful or failed and returns.
This particular run() method:
checks to make sure it can read the file it was given (and throws a Helios::Error::InvalidArg exception if it can't)
calls a method to parse the ID3 tags and other info of the MP3 file
calls a method to update the index table in the database with the new MP3 info
marks the job as successful unless any kind of exception was thrown. If any kind of exception was thrown (either by throwing a Helios::Error exception, calling die(), or some other method), run() will log the error in the Helios log and mark the job as failed.
Though Helios applications can become very complex, every service class follows this same basic, simple pattern. This makes it easy in most cases to write Helios applications.
OTHER METHODS
parseMP3Info($filename)
Given a filename, parseMP3info() returns an MP3::Info object with information on the given MP3 file.
updateDb($filename, $mp3info_object)
Given the MP3 file and the MP3::Info object with that file's info, updateDb() adds the information on that MP3 to the database table, either through an UPDATE (if the filename is already in the table) or an INSERT (if the filename isn't already there).
Note that this method uses the Helios::Service->dbConnect() method to connect to the database, and uses database connection information set in the Helios configuration subsystem. All the method need do is call the getConfig() method, and it has a hash with all of the configuration parameters for the current application running on the current host.
AUTHOR
Andrew Johnson, <lajandy at cpan dotorg>
COPYRIGHT AND LICENSE
Copyright (C) 2012 by Andrew Johnson.
Portions of this software are Copyright (C) 2014 by Logical Helion, LLC where noted.
This library is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.