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

Csv background job #1281

Merged
merged 16 commits into from
Dec 20, 2024
Merged

Csv background job #1281

merged 16 commits into from
Dec 20, 2024

Conversation

jmilljr24
Copy link
Collaborator

@jmilljr24 jmilljr24 commented Dec 19, 2024

🔗 Issue

✍️ Description

This adds a background job to process the csv import. Some changes had to be made to the import service but where minor enough where the service could be run independent of the background job if needed.

This uses Active Job for the background job and uses Turbo::StreamsChannel to broadcast the update when the job is completed.

Tests updated.

📷 Screenshots/Demos

Screencast.from.2024-12-19.07-19-35.webm

app/jobs/csv_import_job.rb Outdated Show resolved Hide resolved
Comment on lines 43 to 48
Turbo::StreamsChannel.broadcast_replace_to @file.signed_id,
target: "results",
partial: "organizations/staff/external_form_upload/upload_results",
locals: {
import: Status.new(@errors.empty?, @count, @no_match, @errors)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Broadcast the import status when the import is complete.

@@ -1,21 +1,21 @@
<turbo-frame id="results">
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was not actually doing anything with a turbo frame so a div is more appropriate.

</small>
</div>
<div class="ps-2">
<%= form.submit t("general.attach"), class: "btn btn-outline-success" %>
</div>
</div>
<% end %>
<%= turbo_frame_tag "results" %>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved to the external form index. This partial is used in multiple locations and the results are really only need for the csv import.

Copy link
Collaborator

@kasugaijin kasugaijin left a comment

Choose a reason for hiding this comment

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

Nice! @jmilljr24 Very cool. Just one comment re tenant. It would be good to get this into production and test it, soon. I will be adding baja to prod later on today (they won't be uploading form data any time soon as there's not much point without adopters signing up so no major rush).

@jmilljr24
Copy link
Collaborator Author

@kasugaijin I'll start working on fixing the tests! Thanks for taking a look.

@jmilljr24 jmilljr24 marked this pull request as ready for review December 20, 2024 15:57
@jmilljr24
Copy link
Collaborator Author

I'm open to suggestions on testing.

I decided to remove some things from the controller test as it seemed beyond the scope of the controller and overly complicated things. The csv service has good test coverage so I don't think we need to duplicate that in the controller test. I didn't add any tests for the job simply because there really is no additional logic in the job other than calling the service.

Copy link
Collaborator

@kasugaijin kasugaijin left a comment

Choose a reason for hiding this comment

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

Nice work @jmilljr24

@kasugaijin kasugaijin merged commit 3b5823a into main Dec 20, 2024
5 checks passed
@kasugaijin kasugaijin deleted the csv-backround-job branch December 20, 2024 16:48
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.

2 participants