Create an scan Library celery task
This commit is contained in:
parent
dc73012ca7
commit
50f002fa73
|
@ -836,6 +836,11 @@ CELERY_BEAT_SCHEDULE = {
|
||||||
),
|
),
|
||||||
"options": {"expires": 60 * 60},
|
"options": {"expires": 60 * 60},
|
||||||
},
|
},
|
||||||
|
"music.library.schedule_remote_scan": {
|
||||||
|
"task": "music.library.schedule_scan",
|
||||||
|
"schedule": crontab(day_of_week="1", minute="0", hour="2"),
|
||||||
|
"options": {"expires": 60 * 60 * 24},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if env.bool("ADD_ALBUM_TAGS_FROM_TRACKS", default=True):
|
if env.bool("ADD_ALBUM_TAGS_FROM_TRACKS", default=True):
|
||||||
|
|
|
@ -79,6 +79,19 @@ def get_cover_from_fs(dir_path):
|
||||||
return {"mimetype": m, "content": c.read()}
|
return {"mimetype": m, "content": c.read()}
|
||||||
|
|
||||||
|
|
||||||
|
@celery.app.task(name="music.library.schedule_remote_scan")
|
||||||
|
def schedule_scan_for_all_remote_libraries():
|
||||||
|
from funkwhale_api.federation import actors
|
||||||
|
|
||||||
|
libraries = models.Library.objects.all().prefetch_related()
|
||||||
|
actor = actors.get_service_actor()
|
||||||
|
|
||||||
|
for library in libraries:
|
||||||
|
if library.actor.is_local:
|
||||||
|
continue
|
||||||
|
library.schedule_scan(actor)
|
||||||
|
|
||||||
|
|
||||||
@celery.app.task(name="music.start_library_scan")
|
@celery.app.task(name="music.start_library_scan")
|
||||||
@celery.require_instance(
|
@celery.require_instance(
|
||||||
models.LibraryScan.objects.select_related().filter(status="pending"), "library_scan"
|
models.LibraryScan.objects.select_related().filter(status="pending"), "library_scan"
|
||||||
|
@ -90,6 +103,10 @@ def start_library_scan(library_scan):
|
||||||
library_scan.status = "errored"
|
library_scan.status = "errored"
|
||||||
library_scan.save(update_fields=["status", "modification_date"])
|
library_scan.save(update_fields=["status", "modification_date"])
|
||||||
raise
|
raise
|
||||||
|
if "errors" in data.keys():
|
||||||
|
library_scan.status = "errored"
|
||||||
|
library_scan.save(update_fields=["status", "modification_date"])
|
||||||
|
raise Exception("Error from remote server : " + str(data))
|
||||||
library_scan.modification_date = timezone.now()
|
library_scan.modification_date = timezone.now()
|
||||||
library_scan.status = "scanning"
|
library_scan.status = "scanning"
|
||||||
library_scan.total_files = data["totalItems"]
|
library_scan.total_files = data["totalItems"]
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Add a celery task to scan remote library (#1712)
|
Loading…
Reference in New Issue