From cb52bc5daa626c57149eb01c08f10a813416fb77 Mon Sep 17 00:00:00 2001 From: 1maple1 <160027655+1maple1@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:46:03 +0000 Subject: [PATCH 1/6] file trigger remove callbacks field --- brewtils/models.py | 9 +++------ brewtils/schemas.py | 1 - 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/brewtils/models.py b/brewtils/models.py index fa594a49..fe104a40 100644 --- a/brewtils/models.py +++ b/brewtils/models.py @@ -1405,26 +1405,24 @@ def scheduler_kwargs(self): class FileTrigger(BaseModel): schema = "FileTriggerSchema" - def __init__(self, pattern=None, path=None, recursive=None, callbacks=None): + def __init__(self, pattern=None, path=None, recursive=None): self.pattern = pattern self.path = path self.recursive = recursive - self.callbacks = callbacks def __str__(self): return repr(self) def __repr__(self): - return "" % ( + return "" % ( self.pattern, self.path, self.recursive, - self.callbacks, ) @property def scheduler_attributes(self): - return ["pattern", "path", "recursive", "callbacks"] + return ["pattern", "path", "recursive"] @property def scheduler_kwargs(self): @@ -1434,7 +1432,6 @@ def scheduler_kwargs(self): "pattern": self.pattern, "path": self.path, "recursive": self.recursive, - "callbacks": self.callbacks, } ) diff --git a/brewtils/schemas.py b/brewtils/schemas.py index 92427abd..173e92e1 100644 --- a/brewtils/schemas.py +++ b/brewtils/schemas.py @@ -489,7 +489,6 @@ class FileTriggerSchema(BaseSchema): pattern = fields.List(fields.Str(), allow_none=True) path = fields.Str(allow_none=True) recursive = fields.Bool(allow_none=True) - callbacks = fields.Dict(fields.Bool(), allow_none=True) class ConnectionSchema(BaseSchema): From 91093fbc30ce69391119c58bcc258f7fe49f252e Mon Sep 17 00:00:00 2001 From: 1maple1 <160027655+1maple1@users.noreply.github.com> Date: Wed, 17 Jul 2024 13:07:42 +0000 Subject: [PATCH 2/6] change file trigger pattern to str --- brewtils/schemas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brewtils/schemas.py b/brewtils/schemas.py index 173e92e1..33b3bdc7 100644 --- a/brewtils/schemas.py +++ b/brewtils/schemas.py @@ -486,7 +486,7 @@ class CronTriggerSchema(BaseSchema): class FileTriggerSchema(BaseSchema): - pattern = fields.List(fields.Str(), allow_none=True) + pattern = fields.Str(allow_none=True) path = fields.Str(allow_none=True) recursive = fields.Bool(allow_none=True) From cf13d1d6b4ae3c486a9233c88c8296687b8c9f58 Mon Sep 17 00:00:00 2001 From: 1maple1 <160027655+1maple1@users.noreply.github.com> Date: Wed, 24 Jul 2024 15:53:54 +0000 Subject: [PATCH 3/6] FileTrigger model tests --- brewtils/models.py | 2 +- brewtils/test/comparable.py | 4 +++- brewtils/test/fixtures.py | 37 +++++++++++++++++++++++++++++++++++++ test/models_test.py | 14 ++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/brewtils/models.py b/brewtils/models.py index fe104a40..99cda6e4 100644 --- a/brewtils/models.py +++ b/brewtils/models.py @@ -1414,7 +1414,7 @@ def __str__(self): return repr(self) def __repr__(self): - return "" % ( + return "" % ( self.pattern, self.path, self.recursive, diff --git a/brewtils/test/comparable.py b/brewtils/test/comparable.py index 1dda4a73..f8c3c3f1 100644 --- a/brewtils/test/comparable.py +++ b/brewtils/test/comparable.py @@ -20,6 +20,7 @@ CronTrigger, DateTrigger, Event, + FileTrigger, Garden, Instance, IntervalTrigger, @@ -191,7 +192,8 @@ def _assert_wrapper(obj1, obj2, expected_type=None, do_raise=False, **kwargs): assert_queue_equal = partial(_assert_wrapper, expected_type=Queue) assert_request_template_equal = partial(_assert_wrapper, expected_type=RequestTemplate) assert_trigger_equal = partial( - _assert_wrapper, expected_type=(CronTrigger, DateTrigger, IntervalTrigger) + _assert_wrapper, + expected_type=(CronTrigger, DateTrigger, FileTrigger, IntervalTrigger), ) assert_request_file_equal = partial(_assert_wrapper, expected_type=RequestFile) assert_runner_equal = partial(_assert_wrapper, expected_type=Runner) diff --git a/brewtils/test/fixtures.py b/brewtils/test/fixtures.py index 3996cc8b..084417bd 100644 --- a/brewtils/test/fixtures.py +++ b/brewtils/test/fixtures.py @@ -13,6 +13,7 @@ CronTrigger, DateTrigger, Event, + FileTrigger, Garden, Instance, IntervalTrigger, @@ -608,6 +609,15 @@ def cron_job_dict(job_dict, cron_trigger_dict): return dict_copy +@pytest.fixture +def file_job_dict(job_dict, file_trigger_dict): + """A file job represented as a dictionary.""" + dict_copy = copy.deepcopy(job_dict) + dict_copy["trigger_type"] = "file" + dict_copy["trigger"] = file_trigger_dict + return dict_copy + + @pytest.fixture def interval_job_dict(job_dict, interval_trigger_dict): """An interval job represented as a dictionary.""" @@ -659,6 +669,16 @@ def bg_cron_job(cron_job_dict, bg_request_template, bg_cron_trigger, ts_dt): return Job(**dict_copy) +@pytest.fixture +def bg_file_job(file_job_dict, bg_request_template, bg_file_trigger): + """A beer garden interval job""" + dict_copy = copy.deepcopy(file_job_dict) + dict_copy["next_run_time"] = None + dict_copy["trigger"] = bg_file_trigger + dict_copy["request_template"] = bg_request_template + return Job(**dict_copy) + + @pytest.fixture def bg_interval_job(interval_job_dict, bg_request_template, bg_interval_trigger, ts_dt): """A beer garden interval job""" @@ -756,6 +776,23 @@ def bg_date_trigger(date_trigger_dict, ts_dt): return DateTrigger(**dict_copy) +@pytest.fixture +def file_trigger_dict(): + """A file trigger as a dictionary""" + return { + "path": "./input", + "pattern": "*", + "recursive": False, + } + + +@pytest.fixture +def bg_file_trigger(file_trigger_dict): + """A file trigger as a model""" + dict_copy = copy.deepcopy(file_trigger_dict) + return FileTrigger(**dict_copy) + + @pytest.fixture def bg_request_file(request_file_dict): """A request file as a model""" diff --git a/test/models_test.py b/test/models_test.py index ec3f40dc..93c6b863 100644 --- a/test/models_test.py +++ b/test/models_test.py @@ -566,6 +566,15 @@ def test_scheduler_kwargs(self, bg_date_trigger, ts_dt_utc): } +class TestFileTrigger(object): + def test_schedule_kwargs_default(self, bg_file_trigger): + assert bg_file_trigger.scheduler_kwargs == { + "path": "./input", + "pattern": "*", + "recursive": False, + } + + class TestIntervalTrigger(object): def test_scheduler_kwargs_default(self): assert IntervalTrigger(timezone="utc").scheduler_kwargs == { @@ -631,6 +640,11 @@ def test_scheduler_kwargs( "", "", ), + ( + lazy_fixture("bg_file_trigger"), + "", + "", + ), ( lazy_fixture("bg_interval_trigger"), "", From 395cb79d8a486ed1507a8952bdbcdba700e0f611 Mon Sep 17 00:00:00 2001 From: 1maple1 <160027655+1maple1@users.noreply.github.com> Date: Wed, 24 Jul 2024 12:51:39 -0400 Subject: [PATCH 4/6] Update models.py --- brewtils/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brewtils/models.py b/brewtils/models.py index 99cda6e4..53e9f09c 100644 --- a/brewtils/models.py +++ b/brewtils/models.py @@ -99,8 +99,9 @@ class Events(Enum): TOPIC_CREATED = 54 TOPIC_UPDATED = 55 TOPIC_REMOVED = 56 + DIRECTORY_FILE_CHANGE = 57 - # Next: 57 + # Next: 58 class BaseModel(object): From b5b3ac148fd933c53cba66e0c8151a2689c0fa99 Mon Sep 17 00:00:00 2001 From: 1maple1 <160027655+1maple1@users.noreply.github.com> Date: Tue, 30 Jul 2024 16:37:27 +0000 Subject: [PATCH 5/6] Add dir file change event --- brewtils/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brewtils/models.py b/brewtils/models.py index 99cda6e4..53e9f09c 100644 --- a/brewtils/models.py +++ b/brewtils/models.py @@ -99,8 +99,9 @@ class Events(Enum): TOPIC_CREATED = 54 TOPIC_UPDATED = 55 TOPIC_REMOVED = 56 + DIRECTORY_FILE_CHANGE = 57 - # Next: 57 + # Next: 58 class BaseModel(object): From 79007a9347e4bdb187529537614e1e76fc6f520a Mon Sep 17 00:00:00 2001 From: 1maple1 <160027655+1maple1@users.noreply.github.com> Date: Thu, 1 Aug 2024 13:43:27 +0000 Subject: [PATCH 6/6] Add file trigger monitor options --- brewtils/models.py | 30 +++++++++++++++++++++++++++--- brewtils/schemas.py | 4 ++++ brewtils/test/fixtures.py | 4 ++++ test/models_test.py | 14 ++++++++++++-- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/brewtils/models.py b/brewtils/models.py index 53e9f09c..344c5c64 100644 --- a/brewtils/models.py +++ b/brewtils/models.py @@ -1406,24 +1406,44 @@ def scheduler_kwargs(self): class FileTrigger(BaseModel): schema = "FileTriggerSchema" - def __init__(self, pattern=None, path=None, recursive=None): + def __init__( + self, + pattern=None, + path=None, + recursive=None, + create=None, + modify=None, + move=None, + delete=None, + ): self.pattern = pattern self.path = path self.recursive = recursive + self.create = create + self.modify = modify + self.move = move + self.delete = delete def __str__(self): return repr(self) def __repr__(self): - return "" % ( + return ( + "" + ) % ( self.pattern, self.path, self.recursive, + self.create, + self.modify, + self.move, + self.delete, ) @property def scheduler_attributes(self): - return ["pattern", "path", "recursive"] + return ["pattern", "path", "recursive", "create", "modify", "move", "delete"] @property def scheduler_kwargs(self): @@ -1433,6 +1453,10 @@ def scheduler_kwargs(self): "pattern": self.pattern, "path": self.path, "recursive": self.recursive, + "create": self.create, + "modify": self.modify, + "move": self.move, + "delete": self.delete, } ) diff --git a/brewtils/schemas.py b/brewtils/schemas.py index 33b3bdc7..02155e79 100644 --- a/brewtils/schemas.py +++ b/brewtils/schemas.py @@ -489,6 +489,10 @@ class FileTriggerSchema(BaseSchema): pattern = fields.Str(allow_none=True) path = fields.Str(allow_none=True) recursive = fields.Bool(allow_none=True) + create = fields.Bool(allow_none=True) + modify = fields.Bool(allow_none=True) + move = fields.Bool(allow_none=True) + delete = fields.Bool(allow_none=True) class ConnectionSchema(BaseSchema): diff --git a/brewtils/test/fixtures.py b/brewtils/test/fixtures.py index 084417bd..95f41a30 100644 --- a/brewtils/test/fixtures.py +++ b/brewtils/test/fixtures.py @@ -783,6 +783,10 @@ def file_trigger_dict(): "path": "./input", "pattern": "*", "recursive": False, + "create": True, + "modify": False, + "move": False, + "delete": False, } diff --git a/test/models_test.py b/test/models_test.py index 93c6b863..366e2c94 100644 --- a/test/models_test.py +++ b/test/models_test.py @@ -572,6 +572,10 @@ def test_schedule_kwargs_default(self, bg_file_trigger): "path": "./input", "pattern": "*", "recursive": False, + "create": True, + "modify": False, + "move": False, + "delete": False, } @@ -642,8 +646,14 @@ def test_scheduler_kwargs( ), ( lazy_fixture("bg_file_trigger"), - "", - "", + ( + "" + ), + ( + "" + ), ), ( lazy_fixture("bg_interval_trigger"),