The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

IO::Iron::IronWorker::Client - IronWorker Client.

VERSION

Version 0.03

SYNOPSIS

        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 );

REQUIREMENTS

See IO::Iron for requirements.

DESCRIPTION

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.

IronWorker Cloud Parallel Workers

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/]

Using the IronWorker Client Library

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.

Commands

After creating the client three sets of commands is available:

Commands for operating code packages:
list_code_packages()
update_code_package(params)
get_info_about_code_package(code_package_id)
delete_code_package(code_package_id)
download_code_package(code_package_id, params)
list_code_package_revisions(code_package_id)
Commands for operating tasks: (NOT YET IMPLEMENTED)
queue_task
get_info_about_task
list_tasks
get_tasks_log
set_tasks_progress
retry_task
cancel_task
Commands for operating scheduled tasks: (NOT YET IMPLEMENTED)
list_scheduled_tasks
schedule_task
get_info_about_scheduled_task
cancel_scheduled_task

Operating code packages

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 );

Operating tasks: (NOT YET IMPLEMENTED)

Operating scheduled tasks: (NOT YET IMPLEMENTED)

Exceptions

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.
                }
        };

SUBROUTINES/METHODS

new

Creator function.

list_code_packages

Return a list of hashes containing information about every code package in IronWorker.

Params: [None]
Return: List of hashes.

See "get_info_about_code_package" for an example of the returned hashes.

update_code_package

Update an IronWorker code package.

Params: .
Return: new code package id == success.
Exception: IronHTTPCallException if fails. (IronHTTPCallException: status_code=<HTTP status code> response_message=<response_message>)

get_info_about_code_package

Params: code package id.
Return: a hash containing info about code package. Exception if code packages does not exist.
Exception: IronHTTPCallException if fails. (IronHTTPCallException: status_code=<HTTP status code> response_message=<response_message>)

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_code_package

Delete an IronWorker code package.

Params: code package id. Code package must exist. If not, fails with an exception.
Return: 1 == success.
Exception: IronHTTPCallException if fails. (IronHTTPCallException: status_code=<HTTP status code> response_message=<response_message>)

download_code_package

Download an IronWorker code package.

Params: code package id. Code package must exist. If not, fails with an exception. subparam: revision.
Return: the code package zipped.
Exception: IronHTTPCallException if fails. (IronHTTPCallException: status_code=<HTTP status code> response_message=<response_message>)

list_code_package_revisions

Return a list of hashes containing information about one code package revisions.

Params: code package id. Code package must exist. If not, fails with an exception.
Return: List of hashes.
Exception: IronHTTPCallException if fails. (IronHTTPCallException: status_code=<HTTP status code> response_message=<response_message>)

AUTHOR

Mikko Koivunalho, <mikko.koivunalho at iki.fi>

BUGS

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.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc IO::Iron::IronWorker::Client

You can also look for information at:

ACKNOWLEDGMENTS

Cool idea, "workers in the cloud": http://www.iron.io/.

LICENSE AND COPYRIGHT

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.