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

Migrate core logic of importchannel to a utility function and update associated tasks #13099

Merged
merged 6 commits into from
Mar 7, 2025

Conversation

thesujai
Copy link
Contributor

Summary

This refactors the importchannel command and its related tasks

  1. Moved the channel transfer logic to a utility function(Which originally was inside the management function)
  2. Updated the channel import tasks to use the utility function instead of calling the importchannel command
  3. Moved import_channel_by_id to channel_import.py util where the function is suited to be

References

Fixes #13095
Subtask of #9266

Reviewer guidance

NA

@github-actions github-actions bot added the DEV: backend Python, databases, networking, filesystem... label Feb 20, 2025
@@ -587,15 +581,11 @@ def diskimport(
drive = get_mounted_drive_by_id(drive_id)
Copy link
Contributor Author

@thesujai thesujai Feb 20, 2025

Choose a reason for hiding this comment

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

This line is duplicated at line 594. Is it a bug or is there any purpose for this?

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 it's a bug, but it definitely looks unnecessary the second time. Probably just copy pasted from somewhere else.

logger = logging.getLogger(__name__)


def start_file_transfer(job, filetransfer, channel_id, dest, no_upgrade, contentfolder):
Copy link
Member

@rtibbles rtibbles Feb 20, 2025

Choose a reason for hiding this comment

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

For both of these functions, I would like it if we did not pass in job as a first argument, and instead invoked get_current_job inside the function itself.

What you would then need is a dummy job in the case where the function is not running in a task runner context, that just does a noop for all the methods of the job class (this way you don't need to keep on checking if the job exists or not).

@rtibbles
Copy link
Member

This makes sense so far, I'd want the test updated, and not just skipped, before we merge, and I think not passing in the job into the functions is preferable - because that will eventually allow us to phase out the AsyncCommand class (passing the self into the function as the job is depending on methods defined on the AsyncCommand).

@thesujai
Copy link
Contributor Author

Thank you @rtibbles . I will update it by tomorrow:)

@thesujai
Copy link
Contributor Author

Updated the utils functions as well as importchannel tests

@rtibbles rtibbles self-assigned this Feb 25, 2025
Copy link
Member

@rtibbles rtibbles left a comment

Choose a reason for hiding this comment

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

This is looking really excellent - great work on this. I'll ask our QA team to confirm the workflows are still working as expected, and we should be ready to merge!

@rtibbles
Copy link
Member

@pcenov @radinamatic we would need to test reviewing a new channel listing from Studio, from disk, and also bulk importing a channel all at once, without viewing the listing.

@pcenov pcenov self-requested a review March 5, 2025 11:28
pcenov
pcenov previously requested changes Mar 5, 2025
Copy link
Member

@pcenov pcenov left a comment

Choose a reason for hiding this comment

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

Hi @rtibbles and @thesujai - unfortunately it's not possible to import a channel or resources in any way. I'm getting a Uncaught (in promise) TypeError: An id must be specified error in the console:

es

2025-03-05_13-41-56.mp4

Logs: logs.zip

@thesujai
Copy link
Contributor Author

thesujai commented Mar 5, 2025

@pcenov Thank you:)
@rtibbles tasks.job.Job is not inheriting JobProgressMixin like AsyncCommand is doing. Missed that for sure. So as a result methods like start_progress and is_cancelled are not accessible by the job object being created at the start of the new functions

@rtibbles
Copy link
Member

rtibbles commented Mar 5, 2025

Ah, yes, you would need to update the methods to those on the job object, not how they are proxied via the mixin. Sorry, I should probably have caught this sooner!

logger = logging.getLogger(__name__)


class JobProgress(JobProgressMixin):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Introducing a adapter class is fine? Or will there be problems now or in the future?

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to migrate to directly accessing the job object rather than continuing the indirection.

Copy link
Member

Choose a reason for hiding this comment

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

Most of the methods are just very thin wrappers around job object methods, so it would be better to remove the extra layer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

re-defining those methods inside this JobProgress would work so?

@thesujai thesujai force-pushed the importchannel-refactor branch from 9fde1c8 to 4e7ce07 Compare March 6, 2025 20:10
@thesujai
Copy link
Contributor Author

thesujai commented Mar 6, 2025

Should work now!

@pcenov
Copy link
Member

pcenov commented Mar 7, 2025

Hi @thesujai and @rtibbles - I confirm that now all of the import scenarios are functioning correctly.

@rtibbles while regression testing I noticed that for some reason only on my Windows 11 laptop the export to USB is not working (works fine on a Windows 10 laptop). Could you take a look at the logs to see whether the error is indicating whether this is something device specific or it's something else: win11-logs.zip

@rtibbles
Copy link
Member

rtibbles commented Mar 7, 2025

Hi @pcenov looking at the logs, I do see an error, definitely nothing to do with the changes here, but it looks like the command we are trying to run to get the disk data from Windows is failing for Windows 11!

Copy link
Member

@rtibbles rtibbles left a comment

Choose a reason for hiding this comment

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

Excellent work - code looks good, and QA passes!

@rtibbles rtibbles dismissed pcenov’s stale review March 7, 2025 20:39

QA now confirmed as working! Reported issue unrelated to this PR, filed separately.

@rtibbles rtibbles merged commit 03ed729 into learningequality:develop Mar 7, 2025
36 checks passed
@rtibbles
Copy link
Member

rtibbles commented Mar 7, 2025

Thank you @thesujai for your diligence, hard work, flexibility and good communication to get this wrapped up swiftly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DEV: backend Python, databases, networking, filesystem...
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Core logic for the importchannel command is migrated to utility functions and all associated tasks updated
3 participants