Skip to content
This repository was archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
python-fetcher: adding TRY_AGAIN and NO_DATA constants
Browse files Browse the repository at this point in the history
Signed-off-by: Antal Nemes <[email protected]>
  • Loading branch information
furiel committed Jun 26, 2019
1 parent d20f28b commit 4c71ae3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion chapters/chapter_5/section_6.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ You can implement your own event loop, or integrate an external framework's or l
### API
A python fetcher implementation must be inherited from `syslogng.LogFetcher` class. There is one mandatory method: `fetch()`
- `fetch()`
The `fetch()` method will be called by syslog-ng whenever syslog-ng is ready to process a new message. This method needs to return a tuple of form (status, syslogng.LogMessage). Status can be `LogFetcher.FETCH_ERROR`, `LogFetcher.FETCH_NOT_CONNECTED` or `LogFetcher.FETCH_SUCCESS`.
The `fetch()` method will be called by syslog-ng whenever syslog-ng is ready to process a new message. This method needs to return a tuple of form (status, syslogng.LogMessage). Status can be `LogFetcher.FETCH_ERROR`, `LogFetcher.FETCH_NOT_CONNECTED`, `LogFetcher.FETCH_SUCCESS`, `LogFetcher.FETCH_TRY_AGAIN` and `LogFetcher.FETCH_TRY_NO_DATA`
The `LogFetcher.FETCH_ERROR` status will result in a `close()` `open()` call, waiting `time-reopen()` seconds in between.
The `LogFetcher.FETCH_NOT_CONNECTED` will result in an `open()` call after `time-reopen()` seconds in between.
The `LogFetcher.FETCH_SUCCESS` status means the fetch was successful, and syslog-ng can handle the returned message.
The `LogFetcher.FETCH_TRY_AGAIN` status means fetcher cannot provide message this time, but make the source call fetch as soon as possible.
The `LogFetcher.FETCH_NO_DATA` status means there is no data available this time, syslog-ng can wait some time before calling fetch again. The wait time is equal to time-reopen() by default, but it might be overridden if fetch_no_data_delay(sec) is provided.

The following methods are optional: `init()`, `deinit()`, `open()`, `close()`, `request_exit()`

Expand Down Expand Up @@ -76,6 +78,8 @@ class MyFetcher(LogFetcher):
response = self.connection.getresponse()
# return LogFetcher.FETCH_ERROR,
# return LogFetcher.FETCH_NOT_CONNECTED,
# return LogFetcher.FETCH_TRY_AGAIN,
# return LogFetcher.FETCH_NO_DATA,
return LogFetcher.FETCH_SUCCESS, LogMessage(response.read())
def request_exit(self):
Expand Down

0 comments on commit 4c71ae3

Please sign in to comment.