NAME
MangoX::Queue::Tutorial
QUICK START
Non-blocking mode using Mojo::IOLoop
Get a Mango collection
my
$collection
=
$mango
->db(
'foo'
)->collection(
'bar'
);
Create a MangoX::Queue
my
$queue
= MangoX::Queue->new(
collection
=>
$collection
);
Add a job to the queue
enqueue
$queue
'job_name'
=>
sub
{
my
(
$job_id
) =
@_
;
# ...
}
Consume the queue to receive jobs
my
$consumer
= consume
$queue
sub
{
my
(
$job
) =
@_
;
# ...
};
Stop consuming the queue
release
$queue
$consumer
;
Update the job status in the queue
$job
->{status} =
'Finished'
;
update
$queue
$job
=>
sub
{
my
(
$job
) =
@_
;
# ...
};
Remove the job from the queue
dequeue
$queue
$job
=>
sub
{
# ...
};
Blocking mode
Get a Mango collection
my
$collection
=
$mango
->db(
'foo'
)->collection(
'bar'
);
Create a MangoX::Queue
my
$queue
= MangoX::Queue->new(
collection
=>
$collection
);
Add a job to the queue
my
$job_id
= enqueue
$queue
'job_name'
;
Consume the queue to receive jobs
while
(
my
$job
= consume
$queue
) {
# ...
};
Update the job status in the queue
$job
->{status} =
'Finished'
;
my
$job
= update
$queue
$job
;
Remove the job from the queue
dequeue
$queue
$job
;