-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Noop processing strategy (#376)
This can be useful when you consume a message and do not wish to commit he offset back to Kafka [1]. [1]: The sentry uptime-checker project has this requirement as it is using Kafka as a mechanism to store configurations. By using log compaction we never actually want to commit a log offset, and want to read the entire log every time.
- Loading branch information
1 parent
8b0bdee
commit ab87c3a
Showing
9 changed files
with
90 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Optional, Union | ||
|
||
from arroyo.processing.strategies.abstract import ProcessingStrategy | ||
from arroyo.types import FilteredPayload, Message, TStrategyPayload | ||
|
||
|
||
class Noop( | ||
ProcessingStrategy[Union[FilteredPayload, object]], | ||
): | ||
""" | ||
Noop strategy that takes a message and does nothing. | ||
""" | ||
|
||
def __init__(self) -> None: | ||
pass | ||
|
||
def submit( | ||
self, message: Message[Union[FilteredPayload, TStrategyPayload]] | ||
) -> None: | ||
pass | ||
|
||
def poll(self) -> None: | ||
pass | ||
|
||
def join(self, timeout: Optional[float] = None) -> None: | ||
pass | ||
|
||
def close(self) -> None: | ||
pass | ||
|
||
def terminate(self) -> None: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,5 @@ Messages | |
run_task_with_multiprocessing | ||
produce | ||
commit_offsets | ||
noop | ||
healthcheck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Noop | ||
----------------------------- | ||
|
||
.. automodule:: arroyo.processing.strategies.noop | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use std::time::Duration; | ||
|
||
use crate::types::Message; | ||
|
||
use super::{CommitRequest, ProcessingStrategy, StrategyError, SubmitError}; | ||
|
||
/// Noop strategy that takes a message and does nothing. | ||
/// | ||
/// This can be useful when you do not care to commit an offset. | ||
pub struct Noop {} | ||
|
||
impl<TPayload> ProcessingStrategy<TPayload> for Noop { | ||
fn poll(&mut self) -> Result<Option<CommitRequest>, StrategyError> { | ||
Ok(None) | ||
} | ||
fn submit(&mut self, _message: Message<TPayload>) -> Result<(), SubmitError<TPayload>> { | ||
Ok(()) | ||
} | ||
fn terminate(&mut self) {} | ||
fn join(&mut self, _timeout: Option<Duration>) -> Result<Option<CommitRequest>, StrategyError> { | ||
Ok(None) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from datetime import datetime | ||
|
||
from arroyo.processing.strategies.noop import Noop | ||
from arroyo.types import Message, Partition, Topic, Value | ||
|
||
|
||
def test_noop() -> None: | ||
""" | ||
Test that the interface of the noop strategy is correct. | ||
""" | ||
now = datetime.now() | ||
|
||
strategy = Noop() | ||
partition = Partition(Topic("topic"), 0) | ||
|
||
strategy.submit(Message(Value(b"hello", {partition: 1}, now))) | ||
strategy.poll() | ||
strategy.submit(Message(Value(b"world", {partition: 2}, now))) | ||
strategy.poll() |