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

Skip content import #900

Merged
merged 7 commits into from
Nov 15, 2023
Merged

Skip content import #900

merged 7 commits into from
Nov 15, 2023

Conversation

dbnicholson
Copy link
Member

Like was done with channel imports, skip content import tasks if all the resources are already available. This is needed when the device is online because Kolibri will probe the channel data from the server regardless of whether content is needed or not. While working on this, I noticed that extra channel thumbnail downloads may be skipped if the channel was already present.

Sorry this is a bit big. I wanted to be sure there really wouldn't be any network requests if they weren't needed. That involved a bit of work with the test studio server so that it could respond to all the requests without having them stubbed out.

Fixes: #890

This is already ignored by pre-commit because it's not under version
control, but if you run bare `flake8` it will check it.
These were helpful when I was developing that code, but now they just
add a lot of noise to the test output.
In order for `ContentServer` to support the
`/api/public/v1/channels/lookup/<channel_id>` endpoint, it needs to be
able to introspect the channel database. Ideally this would open the
actual sqlite database and use Kolibri's routines, but that would be
complicated. Instead, copy the input JSON files into the content
directory so the server can get the channel data from them without using
the databases.
When the `ContentServer` is run in a separate process with
`multiprocessing`, none of the log messages are recorded. Instead, use a
separate thread in the current process. All that needs to happen:

* `serve_forever()` is run in a separate thread
* `shutdown()` is called from the main thread
* `server_close()` is called to close the socket

Now that the log messages are visible, it's clear that the thread name
in the handler log message is redundant since our pytest default format
includes the thread name.
Unfortunately, even if Kolibri already has all the content nodes, it
will still probe the remote server for channel metadata. Since that
fails when the device is offline, skip creating the tasks if it appears
all the content nodes are available. This uses the same
`get_import_export_data` helper that Kolibri uses when determining nodes
to download. That's an expensive query, but it appears that's the only
way to reliably determine if a download is needed or not.

Fixes: #890
In order to import an extra channel and its thumbnails, the storage hook
would detect a completed channel import task and then create a thumbnail
import task for that channel dynamically. However, now that channel
import tasks are skipped if the channel is already available, no
completed channel import task would arrive to trigger the thumbnail task
creation.

That's an unlikely scenario since the installation is expected to come
with either no content or fully populated channels, but it can be
handled better. Instead of using 2 tasks, use a single `remoteimport`
task that combines `remotechannelimport` and `remotecontentimport`. The
hook action is kept in case there are existing installations that hadn't
completed the background tasks yet, but hopefully it can be removed
someday.
Mocking these interfaces was hiding the fact that Kolibri was still
making network requests when they weren't expected. Instead, have
`ContentServer` handle them so tests that aren't supposed to make
network requests fail.
@dbnicholson dbnicholson merged commit 1a02673 into master Nov 15, 2023
3 checks passed
@dbnicholson dbnicholson deleted the skip-content-import branch November 15, 2023 16:18
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.

Key on EOS: app does not work offline
2 participants