enqueue method
Enqueues a task with the given data payload.
The data will be JSON-encoded and sent to the function.
Optional options can specify:
- Schedule time (absolute or delay)
- Dispatch deadline
- Task ID (for deduplication)
- Custom headers
- Custom URI
Example:
await queue.enqueue(
{'userId': '123', 'action': 'sendEmail'},
TaskOptions(
scheduleDelaySeconds: 3600, // Send in 1 hour
id: 'unique-task-id',
),
);
Throws FirebaseFunctionsAdminException if the request fails.
Implementation
Future<void> enqueue(
Map<String, dynamic> data, [
TaskOptions? options,
]) async {
final currentScope = _scope;
if (currentScope is! _ExtensionOrKitFunctionScope) {
await _requestHandler.enqueue(data, _functionName, currentScope, options);
return;
}
try {
await _requestHandler.enqueue(data, _functionName, currentScope, options);
} on FirebaseFunctionsAdminException catch (err) {
if (err.errorCode != FunctionsClientErrorCode.notFound) {
rethrow;
}
final tempKitScope = _KitFunctionScope(currentScope.instance);
await _requestHandler.enqueue(data, _functionName, tempKitScope, options);
// Only upgrade the stateful scope to kit if the retry request succeeds
_scope = tempKitScope;
_logFallbackWarning(_functionName, currentScope.instance);
}
}