Guarantee close on store factory close
This commit is contained in:
parent
d133832e73
commit
f00cb9564d
15
shep/store/base.py
Normal file
15
shep/store/base.py
Normal file
@ -0,0 +1,15 @@
|
||||
re_processedname = r'^_?[A-Z,\.]*$'
|
||||
|
||||
|
||||
class StoreFactory:
|
||||
|
||||
def __del__(self):
|
||||
self.close()
|
||||
|
||||
|
||||
def add(self, k):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
def close(self):
|
||||
pass
|
@ -3,7 +3,10 @@ import os
|
||||
import re
|
||||
|
||||
# local imports
|
||||
from .base import re_processedname
|
||||
from .base import (
|
||||
re_processedname,
|
||||
StoreFactory,
|
||||
)
|
||||
|
||||
|
||||
class SimpleFileStore:
|
||||
@ -124,7 +127,7 @@ class SimpleFileStore:
|
||||
pass
|
||||
|
||||
|
||||
class SimpleFileStoreFactory:
|
||||
class SimpleFileStoreFactory(StoreFactory):
|
||||
"""Provide a method to instantiate SimpleFileStore instances that provide persistence for individual states.
|
||||
|
||||
:param path: Filesystem path as base path for states
|
||||
|
@ -4,6 +4,9 @@ import datetime
|
||||
# external imports
|
||||
import redis
|
||||
|
||||
# local imports
|
||||
from .base import StoreFactory
|
||||
|
||||
|
||||
class RedisStore:
|
||||
|
||||
@ -86,7 +89,7 @@ class RedisStore:
|
||||
self.redis.set(k)
|
||||
|
||||
|
||||
class RedisStoreFactory:
|
||||
class RedisStoreFactory(StoreFactory):
|
||||
|
||||
def __init__(self, host='localhost', port=6379, db=0, binary=False):
|
||||
self.redis = redis.Redis(host=host, port=port, db=db)
|
||||
|
@ -4,6 +4,10 @@ import datetime
|
||||
# external imports
|
||||
import rocksdb
|
||||
|
||||
# local imports
|
||||
from .base import StoreFactory
|
||||
|
||||
|
||||
class RocksDbStore:
|
||||
|
||||
def __init__(self, path, db, binary=False):
|
||||
@ -109,7 +113,7 @@ class RocksDbStore:
|
||||
self.db.set(k)
|
||||
|
||||
|
||||
class RocksDbStoreFactory:
|
||||
class RocksDbStoreFactory(StoreFactory):
|
||||
|
||||
def __init__(self, path, binary=False):
|
||||
self.db = rocksdb.DB(path, rocksdb.Options(create_if_missing=True))
|
||||
|
Loading…
Reference in New Issue
Block a user