| 1 | package PAGI::FastAPI::Queue::Driver; | ||
| 2 | |||
| 3 | 4 | ▶ | use v5.38; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 4 | ▶ | use experimental 'class'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 4 | ▶ | use version; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 4 | our $VERSION = qv('v1.7.3'); | |
| 8 | 4 | our $AUTHORITY = 'cpan:MANWAR'; | |
| 9 | |||
| 10 | 4 | ▶ | use Future::AsyncAwait; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | 4 | class PAGI::FastAPI::Queue::Driver { | |
| 13 | 1 | ▶ | async method push ($topic, $payload) { |
|
Subroutine
push: called CC=1 SCAR=0.0
Pod
documented
| |||
| 14 | 1 | die ref($self) . " must implement push()"; | |
| 15 | 4 | } | |
| 16 | |||
| 17 | 1 | ▶ | async method pop ($topic) { |
|
Subroutine
pop: called CC=1 SCAR=0.0
Pod
documented
| |||
| 18 | 1 | die ref($self) . " must implement pop()"; | |
| 19 | 4 | } | |
| 20 | |||
| 21 | 1 | ▶ | async method size ($topic = undef) { |
|
Subroutine
size: called CC=2 SCAR=6.9
Pod
documented
| |||
| 22 | 1 | die ref($self) . " must implement size()"; | |
| 23 | 4 | } | |
| 24 | } | ||
| 25 | |||
| 26 | =encoding utf-8 | ||
| 27 | |||
| 28 | =head1 NAME | ||
| 29 | |||
| 30 | PAGI::FastAPI::Queue::Driver - Abstract Base Class for Message Queue Storage Drivers | ||
| 31 | |||
| 32 | =head1 VERSION | ||
| 33 | |||
| 34 | Version v1.7.3 | ||
| 35 | |||
| 36 | =head1 SYNOPSIS | ||
| 37 | |||
| 38 | package PAGI::FastAPI::Queue::Driver::Custom; | ||
| 39 | |||
| 40 | use v5.38; | ||
| 41 | use experimental 'class'; | ||
| 42 | use Future::AsyncAwait; | ||
| 43 | |||
| 44 | use PAGI::FastAPI::Queue::Driver; | ||
| 45 | |||
| 46 | class PAGI::FastAPI::Queue::Driver::Custom | ||
| 47 | :isa(PAGI::FastAPI::Queue::Driver) { | ||
| 48 | |||
| 49 | async method push ($topic, $payload) { | ||
| 50 | # Enqueue $payload onto $topic asynchronously... | ||
| 51 | return 1; | ||
| 52 | } | ||
| 53 | |||
| 54 | async method pop ($topic) { | ||
| 55 | # Dequeue and return the next item for $topic asynchronously... | ||
| 56 | return $item; | ||
| 57 | } | ||
| 58 | |||
| 59 | async method size ($topic = undef) { | ||
| 60 | # Report pending item count asynchronously... | ||
| 61 | return $count; | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | =head1 DESCRIPTION | ||
| 66 | |||
| 67 | C<PAGI::FastAPI::Queue::Driver> creates the asynchronous abstract interface | ||
| 68 | used for all message queue backends by L<PAGI::FastAPI::Queue>. | ||
| 69 | |||
| 70 | Any new storage drivers (like C<Redis>, C<SQS>, or a queue based on a database) | ||
| 71 | should use this class as a superclass and code the asynchronous methods in | ||
| 72 | it to ensure these methods result in the creation of L instances and | ||
| 73 | consequently, will not block the event loop of PAGI. | ||
| 74 | |||
| 75 | As of version C<v1.1.0>, we have built-in support for in memory message queue by | ||
| 76 | +L<PAGI::FastAPI::Queue::Driver::Memory>. | ||
| 77 | + | ||
| 78 | +We even have demo app created for in memory rate limit: C<eg/memory_queue_demo.pl> | ||
| 79 | + | ||
| 80 | +If you are looking for more specialised options then you have another choice | ||
| 81 | as a separate companion package: L<PAGI::FastAPI::Queue::Driver::Redis>. | ||
| 82 | |||
| 83 | =head1 REQUIRED METHODS | ||
| 84 | |||
| 85 | Subclasses B<must> override the following methods. Calling any of these | ||
| 86 | directly on the base class returns a failed L<Future>. | ||
| 87 | |||
| 88 | =head2 C<push($topic, $payload)> | ||
| 89 | |||
| 90 | my $future = $driver->push($topic, $payload); | ||
| 91 | |||
| 92 | Enqueues C<$payload> (any scalar) onto C<$topic>. Returns a L<Future> | ||
| 93 | resolving to a true value on success. | ||
| 94 | |||
| 95 | =head2 C<pop($topic)> | ||
| 96 | |||
| 97 | my $future = $driver->pop($topic); | ||
| 98 | |||
| 99 | Dequeues and returns a L<Future> resolving to the next pending item for | ||
| 100 | C<$topic>, or C<undef> if C<$topic> is empty or unknown. | ||
| 101 | |||
| 102 | =head2 C<size($topic = undef)> | ||
| 103 | |||
| 104 | my $future = $driver->size($topic); | ||
| 105 | |||
| 106 | Returns a L<Future> resolving to the integer count of pending items in | ||
| 107 | C<$topic>. If C<$topic> is omitted (or C<undef>), should resolve to the | ||
| 108 | total pending item count across all topics. | ||
| 109 | |||
| 110 | =head1 SEE ALSO | ||
| 111 | |||
| 112 | L<PAGI::FastAPI::Queue::Driver::Memory>, L<PAGI::FastAPI::Queue> | ||
| 113 | |||
| 114 | =head1 AUTHOR | ||
| 115 | |||
| 116 | Mohammad Sajid Anwar, C<< <mohammad.anwar at yahoo.com> >> | ||
| 117 | |||
| 118 | =head1 REPOSITORY | ||
| 119 | |||
| 120 | L<https://github.com/manwar/PAGI-FastAPI> | ||
| 121 | |||
| 122 | =head1 BUGS | ||
| 123 | |||
| 124 | Please report any bugs or feature requests through the web interface at L<https://github.com/manwar/PAGI-FastAPI/issues>. | ||
| 125 | I will be notified and then you'll automatically be notified of progress on your | ||
| 126 | bug as I make changes. | ||
| 127 | |||
| 128 | =head1 SUPPORT | ||
| 129 | |||
| 130 | You can find documentation for this module with the perldoc command. | ||
| 131 | |||
| 132 | perldoc PAGI::FastAPI::Queue::Driver | ||
| 133 | |||
| 134 | You can also look for information at: | ||
| 135 | |||
| 136 | =over 4 | ||
| 137 | |||
| 138 | =item * BUG Report | ||
| 139 | |||
| 140 | L<https://github.com/manwar/PAGI-FastAPI/issues> | ||
| 141 | |||
| 142 | =item * Search MetaCPAN | ||
| 143 | |||
| 144 | L<https://metacpan.org/dist/PAGI-FastAPI/> | ||
| 145 | |||
| 146 | =back | ||
| 147 | |||
| 148 | =head1 LICENSE AND COPYRIGHT | ||
| 149 | |||
| 150 | Copyright (C) 2026 Mohammad Sajid Anwar. | ||
| 151 | |||
| 152 | This program is free software; you can redistribute it and/or modify it under | ||
| 153 | the terms of the Artistic License (2.0). | ||
| 154 | |||
| 155 | =cut | ||
| 156 | |||
| 157 | 4 | 1; # End of PAGI::FastAPI::Queue::Driver | |