MCPcopy
hub / github.com/Koed00/django-q / info

Function info

django_q/monitor.py:195–291  ·  view source on GitHub ↗
(broker=None)

Source from the content-addressed store, hash-verified

193
194
195def info(broker=None):
196 if not broker:
197 broker = get_broker()
198 term = Terminal()
199 broker.ping()
200 stat = Stat.get_all(broker=broker)
201 # general stats
202 clusters = len(stat)
203 workers = 0
204 reincarnations = 0
205 for cluster in stat:
206 workers += len(cluster.workers)
207 reincarnations += cluster.reincarnations
208 # calculate tasks pm and avg exec time
209 tasks_per = 0
210 per = _("day")
211 exec_time = 0
212 last_tasks = models.Success.objects.filter(
213 stopped__gte=timezone.now() - timedelta(hours=24)
214 )
215 tasks_per_day = last_tasks.count()
216 if tasks_per_day > 0:
217 # average execution time over the last 24 hours
218 if connection.vendor != "sqlite":
219 exec_time = last_tasks.aggregate(
220 time_taken=Sum(F("stopped") - F("started"))
221 )
222 exec_time = exec_time["time_taken"].total_seconds() / tasks_per_day
223 else:
224 # can't sum timedeltas on sqlite
225 for t in last_tasks:
226 exec_time += t.time_taken()
227 exec_time = exec_time / tasks_per_day
228 # tasks per second/minute/hour/day in the last 24 hours
229 if tasks_per_day > 24 * 60 * 60:
230 tasks_per = tasks_per_day / (24 * 60 * 60)
231 per = _("second")
232 elif tasks_per_day > 24 * 60:
233 tasks_per = tasks_per_day / (24 * 60)
234 per = _("minute")
235 elif tasks_per_day > 24:
236 tasks_per = tasks_per_day / 24
237 per = _("hour")
238 else:
239 tasks_per = tasks_per_day
240 # print to terminal
241 print(term.clear_eos())
242 col_width = int(term.width / 6)
243 print(
244 term.black_on_green(
245 term.center(
246 _(
247 f'-- {Conf.PREFIX.capitalize()} { ".".join(str(v) for v in VERSION)} on {broker.info()} --'
248 )
249 )
250 )
251 )
252 print(

Callers 2

test_infoFunction · 0.90
handleMethod · 0.90

Calls 6

get_brokerFunction · 0.90
get_allMethod · 0.80
time_takenMethod · 0.80
pingMethod · 0.45
infoMethod · 0.45
queue_sizeMethod · 0.45

Tested by 1

test_infoFunction · 0.72