Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File trigger #498

Merged
merged 9 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions brewtils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ class Events(Enum):
TOPIC_REMOVED = 56
REPLICATION_CREATED = 57
REPLICATION_UPDATED = 58
DIRECTORY_FILE_CHANGE = 59

# Next: 59
# Next: 60


class Permissions(Enum):
Expand Down Expand Up @@ -1415,26 +1416,44 @@ 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,
create=None,
modify=None,
move=None,
delete=None,
):
self.pattern = pattern
self.path = path
self.recursive = recursive
self.callbacks = callbacks
self.create = create
self.modify = modify
self.move = move
self.delete = delete

def __str__(self):
return repr(self)

def __repr__(self):
return "<FileTrigger: %s %s %s %s>" % (
return (
"<FileTrigger: pattern=%s, path=%s, recursive=%s, "
"create=%s, modify=%s, move=%s, delete=%s>"
) % (
self.pattern,
self.path,
self.recursive,
self.callbacks,
self.create,
self.modify,
self.move,
self.delete,
)

@property
def scheduler_attributes(self):
return ["pattern", "path", "recursive", "callbacks"]
return ["pattern", "path", "recursive", "create", "modify", "move", "delete"]

@property
def scheduler_kwargs(self):
Expand All @@ -1444,7 +1463,10 @@ def scheduler_kwargs(self):
"pattern": self.pattern,
"path": self.path,
"recursive": self.recursive,
"callbacks": self.callbacks,
"create": self.create,
"modify": self.modify,
"move": self.move,
"delete": self.delete,
}
)

Expand Down
7 changes: 5 additions & 2 deletions brewtils/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,13 @@ 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)
callbacks = fields.Dict(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):
Expand Down
4 changes: 3 additions & 1 deletion brewtils/test/comparable.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
CronTrigger,
DateTrigger,
Event,
FileTrigger,
Garden,
Instance,
IntervalTrigger,
Expand Down Expand Up @@ -201,7 +202,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)
Expand Down
41 changes: 41 additions & 0 deletions brewtils/test/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
CronTrigger,
DateTrigger,
Event,
FileTrigger,
Garden,
Instance,
IntervalTrigger,
Expand Down Expand Up @@ -700,6 +701,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."""
Expand Down Expand Up @@ -751,6 +761,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"""
Expand Down Expand Up @@ -848,6 +868,27 @@ 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,
"create": True,
"modify": False,
"move": False,
"delete": 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"""
Expand Down
24 changes: 24 additions & 0 deletions test/models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,19 @@ 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,
"create": True,
"modify": False,
"move": False,
"delete": False,
}


class TestIntervalTrigger(object):
def test_scheduler_kwargs_default(self):
assert IntervalTrigger(timezone="utc").scheduler_kwargs == {
Expand Down Expand Up @@ -637,6 +650,17 @@ def test_scheduler_kwargs(
"<DateTrigger: run_date=2016-01-01 00:00:00>",
"<DateTrigger: run_date=2016-01-01 00:00:00>",
),
(
lazy_fixture("bg_file_trigger"),
(
"<FileTrigger: pattern=*, path=./input, recursive=False, "
"create=True, modify=False, move=False, delete=False>"
),
(
"<FileTrigger: pattern=*, path=./input, recursive=False, "
"create=True, modify=False, move=False, delete=False>"
),
),
(
lazy_fixture("bg_interval_trigger"),
"<IntervalTrigger: weeks=1, days=1, hours=1, minutes=1, seconds=1>",
Expand Down
Loading