++ed by:

2 non-PAUSE users.

Ian Kent

NAME

MangoX::Queue::Tutorial

QUICK START

Non-blocking mode using Mojo::IOLoop

  1. Get a Mango collection

        my $mango = Mango->new('mongodb://localhost:27017');
        my $collection = $mango->db('foo')->collection('bar');
  2. Create a MangoX::Queue

        my $queue = MangoX::Queue->new(collection => $collection);
  3. Add a job to the queue

        enqueue $queue 'job_name' => sub {
            my ($job_id) = @_;
            # ...
        }
  4. Consume the queue to receive jobs

        my $consumer = consume $queue sub {
            my ($job) = @_;
            # ...
        };
  5. Stop consuming the queue

        release $queue $consumer;
  6. Update the job status in the queue

        $job->{status} = 'Finished';
        update $queue $job => sub {
            my ($job) = @_;
            # ...
        };
  7. Remove the job from the queue

        dequeue $queue $job => sub {
            # ...
        };

Blocking mode

  1. Get a Mango collection

        my $mango = Mango->new('mongodb://localhost:27017');
        my $collection = $mango->db('foo')->collection('bar');
  2. Create a MangoX::Queue

        my $queue = MangoX::Queue->new(collection => $collection);
  3. Add a job to the queue

        my $job_id = enqueue $queue 'job_name';
  4. Consume the queue to receive jobs

        while (my $job = consume $queue) {
            # ...
        };
  5. Update the job status in the queue

        $job->{status} = 'Finished';
        my $job = update $queue $job;
  6. Remove the job from the queue

        dequeue $queue $job;