Skip to content

Conversation

@max-zilla
Copy link
Contributor

@max-zilla max-zilla commented Sep 30, 2022

This renames extractors to listeners (and creates a legacy endpoint for old extractors) as well as includes basic implementation of job feeds (saved searches) and listeners on those feeds. Lots of decisions here we should discuss.

See test_feeds.py for implementation example, still in progress and very rough.

@max-zilla max-zilla marked this pull request as draft September 30, 2022 15:33
@max-zilla max-zilla marked this pull request as ready for review October 12, 2022 13:59
@max-zilla max-zilla changed the title [WIP] Trigger listener on saved search feed when file uploaded Trigger listener on saved search feed when file uploaded Oct 12, 2022
@max-zilla max-zilla changed the title Trigger listener on saved search feed when file uploaded Extractors -> listeners, trigger listeners on saved feeds automatically Oct 12, 2022
@max-zilla max-zilla requested a review from tcnichol October 12, 2022 14:03
Copy link
Contributor

@tcnichol tcnichol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this one and it still works with extractors. Looks good. Marking approved.

@ddey2 ddey2 self-requested a review October 12, 2022 15:29
@tcnichol
Copy link
Contributor

I think the failing test might be due to ListenerIn needing to be a superclass of ExtractorInfo instead of BaseModel, or perhaps the other way around.

Copy link
Member

@lmarini lmarini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add docstrings to all functions and models? We need to start requiring this on all PRs. Thanks!

@lmarini
Copy link
Member

lmarini commented Oct 21, 2022

@lmarini
Copy link
Member

lmarini commented Oct 21, 2022

Are you still in favor or renaming Listeners to EventListeners to be a bit more specific. When looking through the code and documentation I am still wondering if Listeners is still too generic, even for a developer.

@max-zilla
Copy link
Contributor Author

Can you add docstrings to all functions and models? We need to start requiring this on all PRs. Thanks!

Added a bunch of these.

Will you be adding https://github.com/clowder-framework/clowder2/blob/workflow-documentation/backend/docs/source/listeners.md to this PR?

Added with minor updates as well.

Are you still in favor or renaming Listeners to EventListeners to be a bit more specific. When looking through the code and documentation I am still wondering if Listeners is still too generic, even for a developer.

I renamed to EventListeners across the app, although "listeners.py" is still the filename for simplicity.

@max-zilla max-zilla requested a review from lmarini October 25, 2022 19:26
Copy link
Member

@lmarini lmarini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the PR. Left a few more questions / comments as I continue to review this. There is a lot of digest. Thanks!

parameters: List[dict] = []


class EventListenerBase(BaseModel):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to inherit from ExtractorInfo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, my intent was to allow listeners to be registered without requiring v1 extractor info. So submitting a v2 listener to /api/listeners doesn't need extractor_info contents, but /api/extractors does.

more broadly my hope was that we would rethink/redesign extractor_info because it has some limitations/bloat. however there is some tension between doing that and getting a working demo sooner with an existing extractor. if it is all too confusing, we can just remove LegacyListener concept and revert v2 models to match v1 and keep extractor/listener framework more or less the same? not sure what is easiest for short vs. long term.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. We can try to keep both. Maybe add a few more comments explaining the difference? As long as we can submit/trigger with current extractors, we are good short term. I don't think this gets in the way of that?

"""v1 Extractors can submit data formatted as a LegacyEventListener (i.e. v1 format) and it will be converted to a v2 EventListener."""

name: str
version: str = "1.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the difference in types between version for EventListenerBase and LegacyEventListener (str vs int)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clowder v1 lets users arbitrarily provide a version with no rules (e.g. "1", "1.0", "v1" "beta" all allowed). I was thinking (before v1 back-compatibility) that version could just be an integer for clarity and simplicity, but after seeing it is just a string field for v1 we should probably use that.

If we use string, "version" might better be called "tag" or something like Docker does? Don't necessarily see a point in enforcing something that can be cast as a float in that case...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clowder v1 lets users arbitrarily provide a version with no rules (e.g. "1", "1.0", "v1" "beta" all allowed). I was thinking (before v1 back-compatibility) that version could just be an integer for clarity and simplicity, but after seeing it is just a string field for v1 we should probably use that.

If we use string, "version" might better be called "tag" or something like Docker does? Don't necessarily see a point in enforcing something that can be cast as a float in that case...

Good point. Tag sounds great. We could also enforce semantic versioning in the string and call it version. But that might be more work. Similar to what npm does.

os.remove(dummy_file)
assert response.status_code == 200

# Verify the message
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to test that the listener was triggered?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not yet. if we had an event log we could check that but it doesn't exist yet. Otherwise we'd have to check RMQ somehow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tcnichol how easily could you add v1 events back into v2? I am looking at the heartbeat PR and will leave comments there soon. It would be a similar approach?


router = APIRouter()

clowder_bucket = os.getenv("MINIO_BUCKET_NAME", "clowder")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is being used.

listeners_found.append(listener.listener_id)

for targ_listener in listeners_found:
queue = "" # TODO: Each extractor gets a queue - routing key same as name?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this default to the listener name so that legacy extractors can be triggered?

@lmarini lmarini merged commit e4b2562 into main Oct 27, 2022
@lmarini lmarini deleted the trigger-listeners-on-feed branch October 27, 2022 16:10
@max-zilla max-zilla restored the trigger-listeners-on-feed branch October 31, 2022 14:30
@max-zilla max-zilla deleted the trigger-listeners-on-feed branch October 31, 2022 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants