mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 20:43:04 +00:00
first recommendation draft
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import time
|
||||
import schedule
|
||||
|
||||
from app.crons.mixes import Mixes
|
||||
from app.utils.threading import background
|
||||
|
||||
|
||||
@background
|
||||
def start_cron_jobs():
|
||||
Mixes().run()
|
||||
|
||||
# schedule.run_pending()
|
||||
@@ -0,0 +1,23 @@
|
||||
import schedule
|
||||
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class CronJob(ABC):
|
||||
"""
|
||||
A cron job that will be run on a regular interval.
|
||||
"""
|
||||
|
||||
def __init__(self, name: str, hours: int):
|
||||
self.name = name
|
||||
self.hours = hours
|
||||
|
||||
schedule.every(self.hours).seconds.do(self.run)
|
||||
|
||||
@abstractmethod
|
||||
def run(self):
|
||||
"""
|
||||
The function that will be called by the cron job.
|
||||
"""
|
||||
...
|
||||
@@ -0,0 +1,15 @@
|
||||
from app.crons.cron import CronJob
|
||||
from app.plugins.mixes import MixesPlugin
|
||||
from app.store.homepage import HomepageStore
|
||||
|
||||
|
||||
class Mixes(CronJob):
|
||||
def __init__(self):
|
||||
super().__init__("mixes", 5)
|
||||
|
||||
def run(self):
|
||||
print("⭐⭐⭐⭐ Mixes cron job running")
|
||||
mixes = MixesPlugin()
|
||||
artist_mixes = mixes.get_artists()
|
||||
|
||||
HomepageStore.set_artist_mixes(artist_mixes)
|
||||
Reference in New Issue
Block a user