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

Local File Agent: Output event with file pointer when writing to file #3242

Merged
merged 1 commit into from Apr 23, 2023

Conversation

krendil
Copy link
Contributor

@krendil krendil commented Mar 30, 2023

Change Local File Agent to also emit events when in write mode. The event emitted contains a file pointer to the local file that was just written or appended to. This makes it more convenient to create workflows that involve writing content to a file and then performing an action on that file.

@krendil krendil changed the title Local File Agent: Output event with file handle when writing to file Local File Agent: Output event with file pointer when writing to file Mar 30, 2023
@krendil
Copy link
Contributor Author

krendil commented Mar 30, 2023

Some context on the use case behind this PR, in case there is already a better way to accomplish the same thing:

I'm trying to create an agent that will import files to Firefly III, through the Firefly Data Importer. In order to import data this way, you need to make a POST request encoded as multi-part/form-data that includes two different files - the data you are importing as well as a JSON configuration file. As far as I can tell, the POST agent only allows you to create multi-part/form-data requests if the data is already a file pointer (and you can only post one file at a time). Creating a Shell agent to run curl has a similar issue, in that you can only add file sections to the multipart request using data that is saved to a file, using the @filename syntax. Therefore, we need to write the data to a file first.

This can be accomplished with the Local File agent, however the Local File agent is a dead-end in terms of event flow in write mode. If I wanted to do anything with the file, I'd need a second Local File agent that watches for the files created by the first agent. This is an unnecessary complication that has a number of downsides, hence this PR to allow the chain to remain connected.

Before:
(Receive data) → (Write to file)
(Watch files) → (POST to Firefly importer)

After:
(Receive data) → (Write to file) → (POST to Firefly importer)

@knu knu requested a review from dsander April 23, 2023 03:03
Copy link
Collaborator

@dsander dsander left a comment

Choose a reason for hiding this comment

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

That makes perfect sense. Thank you for the detailed use case explanation!

@dsander dsander merged commit d4a69d6 into huginn:master Apr 23, 2023
6 checks passed
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.

None yet

2 participants