IO::Iron::IronWorker::Client - IronWorker Client.
Version 0.03
require IO::Iron::IronWorker::Client; my $ironworker_client = IO::Iron::IronWorker::Client->new( {} ); # or use IO::Iron qw(get_ironworker); my $ironworker_client = get_ironworker(); my $unique_code_package_name = 'HelloWorldCode'; my $worker_as_zip; # Zipped Perl script and dependencies. my $unique_code_executable_file_name = 'HelloWorldCode.pl'; my $uploaded = $iron_worker_client->update_code_package( { 'name' => $unique_code_package_name, 'file' => $worker_as_zip, 'file_name' => $unique_code_executable_file_name, 'runtime' => 'perl', } ); my $code_package_id; my @code_packages = $iron_worker_client->list_code_packages( { } ); foreach (@code_packages) { if($_->{'name'} eq $unique_code_package_name) { $code_package_id = $_->{'id'}; last; } } my $code_package = $iron_worker_client->get_info_about_code_package( $code_package_id ); my @code_package_revisions = $iron_worker_client->list_code_package_revisions( $code_package_id ); my $downloaded = $iron_worker_client->download_code_package( $code_package_id, { 'revision' => 1, } ); my $delete_rval = $iron_wkr_queue->delete( $code_package_id );
See IO::Iron for requirements.
IO::Iron::IronWorker is a client for the IronWorker remote worker system at http://www.iron.io/. IronWorker is a cloud based parallel multi-language worker platform. with a REST API. IO::Iron::IronWorker creates a Perl object for interacting with IronWorker. All IronWorker functions are available.
The class IO::Iron::IronWorker::Client instantiates the 'project', IronWorker access configuration.
http://www.iron.io/
IronWorker is a parallel worker platform delivered as a service to Internet connecting applications via its REST interface. Built with distributed cloud applications in mind, it provides on-demand scalability for workers, controls with HTTPS transport and cloud-optimized performance. [see http://www.iron.io/]
IO::Iron::IronWorker::Client is a normal Perl package meant to be used as an object.
require IO::Iron::IronWorker::Client; my $ironworker_client = IO::Iron::IronWorker::Client->new( { } );
Please see IO::Iron for further parameters and general usage.
After creating the client three sets of commands is available:
A code package is simply a script program packed into Zip archive together with its dependency files (other libraries, configuration files, etc.).
After creating the zip file and reading it into a perl variable, upload it. In the following example, the worker contains only one file and we create the archive in the program.
require IO::Iron::IronWorker::Client; use IO::Compress::Zip; $iron_worker_client = IO::Iron::IronWorker::Client->new( { 'config' => 'iron_worker.json' } ); my $worker_as_string_ = <<EOF; print qq{Hello, World!\n}; EOF my $worker_as_zip; my $worker_ IO::Compress::Zip::zip(\$worker_as_string => \$worker_as_zip); my $code_package_return_id = $iron_worker_client->update_code_package( { 'name' => 'HelloWorld_code_package', 'file' => $worker_as_string, 'file_name' => helloworld.pl, 'runtime' => 'perl', } );
With method list_code_packages() you can retrieve information about all the uploaded code packages. The method get_info_about_code_package() will return information about only the requested code package.
my @code_packages = $iron_worker_client->list_code_packages(); foreach (@code_packages) { if($_->{'name'} eq 'HelloWorld_code_package) { $code_package_id = $_->{'id'}; last; } } my $code_package = $iron_worker_client->get_info_about_code_package( $code_package_id );
Method delete_code_package() removes the code package from IronWorker service.
my $deleted = $iron_worker_client->delete_code_package( $code_package_id );
The uploaded code package can be retrieved with method download_code_package(). The downloaded file is a zip archive.
my $downloaded = $iron_worker_client->download_code_package( $code_package_id, { 'revision' => 1, } );
The code packages get revision numbers according to their upload order. The first upload of a code package gets revision number 1. Any subsequent upload of the same code package (same name) will get one higher revision number so the different uploads can be recognized.
my @code_package_revisions = $iron_worker_client->list_code_package_revisions( $code_package_id );
A REST call to IronWorker server may fail for several reason. All failures generate an exception using the Exception::Class package. Class IronHTTPCallException contains the field status_code, response_message and error. Error is formatted as such: IronHTTPCallException: status_code=<HTTP status code> response_message=<response_message>.
use Try::Tiny; use Scalar::Util qw{blessed}; try { my $queried_iron_mq_queue_01 = $iron_mq_client->get_queue($unique_queue_name_01); } catch { die $_ unless blessed $_ && $_->can('rethrow'); if ( $_->isa('IronHTTPCallException') ) { if ($_->status_code == 404) { print "Bad things! Can not just find the catch in this!\n"; } } else { $_->rethrow; # Push the error upwards. } };
Creator function.
Return a list of hashes containing information about every code package in IronWorker.
See "get_info_about_code_package" for an example of the returned hashes.
Update an IronWorker code package.
Sample response (in JSON format):
{ "id": "4eb1b241cddb13606500000b", "project_id": "4eb1b240cddb13606500000a", "name": "MyWorker", "runtime": "ruby", "latest_checksum": "a0702e9e9a84b758850d19ddd997cf4a", "rev": 1, "latest_history_id": "4eb1b241cddb13606500000c", "latest_change": 1328737460598000000 }
Delete an IronWorker code package.
Download an IronWorker code package.
Return a list of hashes containing information about one code package revisions.
Mikko Koivunalho, <mikko.koivunalho at iki.fi>
<mikko.koivunalho at iki.fi>
Please report any bugs or feature requests to bug-io-iron at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=IO-Iron. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-io-iron at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc IO::Iron::IronWorker::Client
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=IO-Iron
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/IO-Iron
CPAN Ratings
http://cpanratings.perl.org/d/IO-Iron
Search CPAN
http://search.cpan.org/dist/IO-Iron/
Cool idea, "workers in the cloud": http://www.iron.io/.
Copyright 2013 Mikko Koivunalho.
This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:
http://www.perlfoundation.org/artistic_license_2_0
Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.
If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.
This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.
This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
To install IO::Iron, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IO::Iron
CPAN shell
perl -MCPAN -e shell install IO::Iron
For more information on module installation, please visit the detailed CPAN module installation guide.