1717from varken import VERSION , BRANCH
1818from varken .sonarr import SonarrAPI
1919from varken .radarr import RadarrAPI
20+ from varken .lidarr import LidarrAPI
2021from varken .iniparser import INIParser
2122from varken .dbmanager import DBManager
2223from varken .helpers import GeoIPHandler
2829PLATFORM_LINUX_DISTRO = ' ' .join (x for x in linux_distribution () if x )
2930
3031
31- def thread ():
32- while schedule .jobs :
33- job = QUEUE .get ()
34- a = job ()
35- if a is not None :
36- schedule .clear (a )
37- QUEUE .task_done ()
32+ def thread (job , ** kwargs ):
33+ worker = Thread (target = job , kwargs = dict (** kwargs ))
34+ worker .start ()
3835
3936
4037if __name__ == "__main__" :
@@ -43,7 +40,8 @@ def thread():
4340 formatter_class = RawTextHelpFormatter )
4441
4542 parser .add_argument ("-d" , "--data-folder" , help = 'Define an alternate data folder location' )
46- parser .add_argument ("-D" , "--debug" , action = 'store_true' , help = 'Use to enable DEBUG logging' )
43+ parser .add_argument ("-D" , "--debug" , action = 'store_true' , help = 'Use to enable DEBUG logging. (Depreciated)' )
44+ parser .add_argument ("-ND" , "--no_debug" , action = 'store_true' , help = 'Use to disable DEBUG logging' )
4745
4846 opts = parser .parse_args ()
4947
@@ -72,10 +70,15 @@ def thread():
7270 enable_opts = ['True' , 'true' , 'yes' ]
7371 debug_opts = ['debug' , 'Debug' , 'DEBUG' ]
7472
75- if not opts .debug :
73+ opts .debug = True
74+
75+ if getenv ('DEBUG' ) is not None :
7676 opts .debug = True if any ([getenv (string , False ) for true in enable_opts
7777 for string in debug_opts if getenv (string , False ) == true ]) else False
7878
79+ elif opts .no_debug :
80+ opts .debug = False
81+
7982 # Initiate the logger
8083 vl = VarkenLogger (data_folder = DATA_FOLDER , debug = opts .debug )
8184 vl .logger .info ('Starting Varken...' )
@@ -98,72 +101,84 @@ def thread():
98101 SONARR = SonarrAPI (server , DBMANAGER )
99102 if server .queue :
100103 at_time = schedule .every (server .queue_run_seconds ).seconds
101- at_time .do (QUEUE . put , SONARR .get_queue ).tag ("sonarr-{}-get_queue" .format (server .id ))
104+ at_time .do (thread , SONARR .get_queue ).tag ("sonarr-{}-get_queue" .format (server .id ))
102105 if server .missing_days > 0 :
103106 at_time = schedule .every (server .missing_days_run_seconds ).seconds
104- at_time .do (QUEUE . put , SONARR .get_missing ).tag ("sonarr-{}-get_missing" .format (server .id ))
107+ at_time .do (thread , SONARR .get_calendar , query = "Missing" ).tag ("sonarr-{}-get_missing" .format (server .id ))
105108 if server .future_days > 0 :
106109 at_time = schedule .every (server .future_days_run_seconds ).seconds
107- at_time .do (QUEUE . put , SONARR .get_future ).tag ("sonarr-{}-get_future" .format (server .id ))
110+ at_time .do (thread , SONARR .get_calendar , query = "Future" ).tag ("sonarr-{}-get_future" .format (server .id ))
108111
109112 if CONFIG .tautulli_enabled :
110113 GEOIPHANDLER = GeoIPHandler (DATA_FOLDER )
111- schedule .every (12 ).to (24 ).hours .do (QUEUE . put , GEOIPHANDLER .update )
114+ schedule .every (12 ).to (24 ).hours .do (thread , GEOIPHANDLER .update )
112115 for server in CONFIG .tautulli_servers :
113116 TAUTULLI = TautulliAPI (server , DBMANAGER , GEOIPHANDLER )
114117 if server .get_activity :
115118 at_time = schedule .every (server .get_activity_run_seconds ).seconds
116- at_time .do (QUEUE . put , TAUTULLI .get_activity ).tag ("tautulli-{}-get_activity" .format (server .id ))
119+ at_time .do (thread , TAUTULLI .get_activity ).tag ("tautulli-{}-get_activity" .format (server .id ))
117120 if server .get_stats :
118121 at_time = schedule .every (server .get_stats_run_seconds ).seconds
119- at_time .do (QUEUE . put , TAUTULLI .get_stats ).tag ("tautulli-{}-get_stats" .format (server .id ))
122+ at_time .do (thread , TAUTULLI .get_stats ).tag ("tautulli-{}-get_stats" .format (server .id ))
120123
121124 if CONFIG .radarr_enabled :
122125 for server in CONFIG .radarr_servers :
123126 RADARR = RadarrAPI (server , DBMANAGER )
124127 if server .get_missing :
125128 at_time = schedule .every (server .get_missing_run_seconds ).seconds
126- at_time .do (QUEUE . put , RADARR .get_missing ).tag ("radarr-{}-get_missing" .format (server .id ))
129+ at_time .do (thread , RADARR .get_missing ).tag ("radarr-{}-get_missing" .format (server .id ))
127130 if server .queue :
128131 at_time = schedule .every (server .queue_run_seconds ).seconds
129- at_time .do (QUEUE .put , RADARR .get_queue ).tag ("radarr-{}-get_queue" .format (server .id ))
132+ at_time .do (thread , RADARR .get_queue ).tag ("radarr-{}-get_queue" .format (server .id ))
133+
134+ if CONFIG .lidarr_enabled :
135+ for server in CONFIG .lidarr_servers :
136+ LIDARR = LidarrAPI (server , DBMANAGER )
137+ if server .queue :
138+ at_time = schedule .every (server .queue_run_seconds ).seconds
139+ at_time .do (thread , LIDARR .get_queue ).tag ("lidarr-{}-get_queue" .format (server .id ))
140+ if server .missing_days > 0 :
141+ at_time = schedule .every (server .missing_days_run_seconds ).seconds
142+ at_time .do (thread , LIDARR .get_calendar , query = "Missing" ).tag (
143+ "lidarr-{}-get_missing" .format (server .id ))
144+ if server .future_days > 0 :
145+ at_time = schedule .every (server .future_days_run_seconds ).seconds
146+ at_time .do (thread , LIDARR .get_calendar , query = "Future" ).tag ("lidarr-{}-get_future" .format (
147+ server .id ))
130148
131149 if CONFIG .ombi_enabled :
132150 for server in CONFIG .ombi_servers :
133151 OMBI = OmbiAPI (server , DBMANAGER )
134152 if server .request_type_counts :
135153 at_time = schedule .every (server .request_type_run_seconds ).seconds
136- at_time .do (QUEUE . put , OMBI .get_request_counts ).tag ("ombi-{}-get_request_counts" .format (server .id ))
154+ at_time .do (thread , OMBI .get_request_counts ).tag ("ombi-{}-get_request_counts" .format (server .id ))
137155 if server .request_total_counts :
138156 at_time = schedule .every (server .request_total_run_seconds ).seconds
139- at_time .do (QUEUE . put , OMBI .get_all_requests ).tag ("ombi-{}-get_all_requests" .format (server .id ))
157+ at_time .do (thread , OMBI .get_all_requests ).tag ("ombi-{}-get_all_requests" .format (server .id ))
140158 if server .issue_status_counts :
141159 at_time = schedule .every (server .issue_status_run_seconds ).seconds
142- at_time .do (QUEUE . put , OMBI .get_issue_counts ).tag ("ombi-{}-get_issue_counts" .format (server .id ))
160+ at_time .do (thread , OMBI .get_issue_counts ).tag ("ombi-{}-get_issue_counts" .format (server .id ))
143161
144162 if CONFIG .sickchill_enabled :
145163 for server in CONFIG .sickchill_servers :
146164 SICKCHILL = SickChillAPI (server , DBMANAGER )
147165 if server .get_missing :
148166 at_time = schedule .every (server .get_missing_run_seconds ).seconds
149- at_time .do (QUEUE . put , SICKCHILL .get_missing ).tag ("sickchill-{}-get_missing" .format (server .id ))
167+ at_time .do (thread , SICKCHILL .get_missing ).tag ("sickchill-{}-get_missing" .format (server .id ))
150168
151169 if CONFIG .unifi_enabled :
152170 for server in CONFIG .unifi_servers :
153171 UNIFI = UniFiAPI (server , DBMANAGER )
154172 at_time = schedule .every (server .get_usg_stats_run_seconds ).seconds
155- at_time .do (QUEUE . put , UNIFI .get_usg_stats ).tag ("unifi-{}-get_usg_stats" .format (server .id ))
173+ at_time .do (thread , UNIFI .get_usg_stats ).tag ("unifi-{}-get_usg_stats" .format (server .id ))
156174
157175 # Run all on startup
158176 SERVICES_ENABLED = [CONFIG .ombi_enabled , CONFIG .radarr_enabled , CONFIG .tautulli_enabled , CONFIG .unifi_enabled ,
159- CONFIG .sonarr_enabled , CONFIG .sickchill_enabled ]
177+ CONFIG .sonarr_enabled , CONFIG .sickchill_enabled , CONFIG . lidarr_enabled ]
160178 if not [enabled for enabled in SERVICES_ENABLED if enabled ]:
161179 vl .logger .error ("All services disabled. Exiting" )
162180 exit (1 )
163181
164- WORKER = Thread (target = thread )
165- WORKER .start ()
166-
167182 schedule .run_all ()
168183
169184 while schedule .jobs :
0 commit comments