Add file
This commit is contained in:
@ -21,11 +21,16 @@ barcode_server:
|
|||||||
# (optional) Time to wait between retries
|
# (optional) Time to wait between retries
|
||||||
retry_interval: 2s
|
retry_interval: 2s
|
||||||
|
|
||||||
# (optional) HTTP push configuration
|
# (optional) Serial push configuration
|
||||||
serial:
|
serial:
|
||||||
# URL to send events to using a request
|
# URL to send events to using a request
|
||||||
path: "/dev/ttyUSB0"
|
path: "/dev/ttyUSB0"
|
||||||
|
|
||||||
|
# (optional) file push configuration
|
||||||
|
file:
|
||||||
|
# URL to send events to using a request
|
||||||
|
path: "/var/www/barcode-server"
|
||||||
|
|
||||||
# (optional) HTTP push configuration
|
# (optional) HTTP push configuration
|
||||||
# http:
|
# http:
|
||||||
# URL to send events to using a request
|
# URL to send events to using a request
|
||||||
|
@ -222,6 +222,15 @@ class AppConfig(ConfigBase):
|
|||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
FILE_PATH = StringConfigEntry(
|
||||||
|
key_path=[
|
||||||
|
CONFIG_NODE_ROOT,
|
||||||
|
CONFIG_NODE_FILE,
|
||||||
|
"path"
|
||||||
|
],
|
||||||
|
required=False
|
||||||
|
)
|
||||||
|
|
||||||
DEVICE_PATTERNS = ListConfigEntry(
|
DEVICE_PATTERNS = ListConfigEntry(
|
||||||
item_type=RegexConfigEntry,
|
item_type=RegexConfigEntry,
|
||||||
item_args={
|
item_args={
|
||||||
|
@ -23,6 +23,7 @@ CONFIG_NODE_SERVER = "server"
|
|||||||
CONFIG_NODE_HTTP = "http"
|
CONFIG_NODE_HTTP = "http"
|
||||||
CONFIG_NODE_MQTT = "mqtt"
|
CONFIG_NODE_MQTT = "mqtt"
|
||||||
CONFIG_NODE_SERIAL = "serial"
|
CONFIG_NODE_SERIAL = "serial"
|
||||||
|
CONFIG_NODE_FILE = "file"
|
||||||
|
|
||||||
CONFIG_NODE_STATS = "stats"
|
CONFIG_NODE_STATS = "stats"
|
||||||
CONFIG_NODE_PORT = "port"
|
CONFIG_NODE_PORT = "port"
|
||||||
|
20
barcode_server/notifier/file.py
Normal file
20
barcode_server/notifier/file.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import logging
|
||||||
|
# import time as sleep
|
||||||
|
|
||||||
|
from prometheus_async.aio import time
|
||||||
|
|
||||||
|
from barcode_server.barcode import BarcodeEvent
|
||||||
|
from barcode_server.notifier import BarcodeNotifier
|
||||||
|
from barcode_server.stats import FILE_NOTIFIER_TIME
|
||||||
|
|
||||||
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class FileNotifier(BarcodeNotifier):
|
||||||
|
|
||||||
|
def __init__(self, path: str):
|
||||||
|
super().__init__()
|
||||||
|
self.path = path
|
||||||
|
|
||||||
|
@time(FILE_NOTIFIER_TIME)
|
||||||
|
async def _send_event(self, event: BarcodeEvent):
|
||||||
|
LOGGER.debug(f"Notified {self.path}: {event.barcode}")
|
@ -63,6 +63,10 @@ class Webserver:
|
|||||||
serial_notifier = SerialNotifier(config.SERIAL_PATH.value, self.usb)
|
serial_notifier = SerialNotifier(config.SERIAL_PATH.value, self.usb)
|
||||||
self.notifiers["serial"] = serial_notifier
|
self.notifiers["serial"] = serial_notifier
|
||||||
|
|
||||||
|
if config.FILE_PATH.value is not None:
|
||||||
|
file_notifier = SerialNotifier(config.FILE_PATH.value)
|
||||||
|
self.notifiers["file"] = file_notifier
|
||||||
|
|
||||||
async def start(self):
|
async def start(self):
|
||||||
# start detecting and reading barcode scanners
|
# start detecting and reading barcode scanners
|
||||||
await self.barcode_reader.start()
|
await self.barcode_reader.start()
|
||||||
|
Reference in New Issue
Block a user