Skip to content

Commit

Permalink
Add basic task worker integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
rtibbles committed Feb 11, 2023
1 parent b514cb1 commit 42dcf10
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions .p4a
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
--ndk-api 23
--permission ACCESS_NETWORK_STATE
--permission FOREGROUND_SERVICE
--worker TaskWorker:taskworker.py
--service remoteshell:remoteshell.py
--presplash assets/icon.png
--presplash-color #FFFFFF
Expand Down
1 change: 1 addition & 0 deletions src/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@


os.environ["KOLIBRI_CHERRYPY_THREAD_POOL"] = "2"
os.environ["KOLIBRI_SCHEDULE_HOOKS"] = "kolibri_tasks.queue_task"

Secure = autoclass("android.provider.Settings$Secure")

Expand Down
32 changes: 32 additions & 0 deletions src/taskworker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import logging
from os import environ

import initialization # noqa: F401 keep this first, to ensure we're set up for other imports
from kolibri_tasks import queue_task
from kolibri_tasks import task_updates
from kolibri.main import initialize

logging.info("Starting Kolibri task worker")

initialize(skip_update=True)

job_id = environ.get('PYTHON_SERVICE_ARGUMENT', '')

from django.db import connection as django_connection

from kolibri.core.tasks.storage import Storage
from kolibri.core.tasks.utils import db_connection

connection = db_connection()

storage = Storage(connection, schedule_hooks=[queue_task], update_hooks=[task_updates])

job = storage.get_job(job_id)

job.execute()

connection.dispose()

# Close any django connections opened here
django_connection.close()

0 comments on commit 42dcf10

Please sign in to comment.