MCPcopy
hub / github.com/celery/celery / rate_limit

Function rate_limit

celery/worker/control.py:259–292  ·  view source on GitHub ↗

Tell worker(s) to modify the rate limit for a task by type. See Also: :attr:`celery.app.task.Task.rate_limit`. Arguments: task_name (str): Type of task to set rate limit for. rate_limit (int, str): New rate limit.

(state, task_name, rate_limit, **kwargs)

Source from the content-addressed store, hash-verified

257 signature='<task_name> <rate_limit (e.g., 5/s | 5/m | 5/h)>',
258)
259def rate_limit(state, task_name, rate_limit, **kwargs):
260 """Tell worker(s) to modify the rate limit for a task by type.
261
262 See Also:
263 :attr:`celery.app.task.Task.rate_limit`.
264
265 Arguments:
266 task_name (str): Type of task to set rate limit for.
267 rate_limit (int, str): New rate limit.
268 """
269 # pylint: disable=redefined-outer-name
270 # XXX Note that this redefines `terminate`:
271 # Outside of this scope that is a function.
272 try:
273 rate(rate_limit)
274 except ValueError as exc:
275 return nok(f'Invalid rate limit string: {exc!r}')
276
277 try:
278 state.app.tasks[task_name].rate_limit = rate_limit
279 except KeyError:
280 logger.error('Rate limit attempt for unknown task %s',
281 task_name, exc_info=True)
282 return nok('unknown task')
283
284 state.consumer.reset_rate_limits()
285
286 if not rate_limit:
287 logger.info('Rate limits disabled for tasks of type %s', task_name)
288 return ok('rate limit disabled successfully')
289
290 logger.info('New rate limit for tasks of type %s: %s.',
291 task_name, rate_limit)
292 return ok('new rate limit set successfully')
293
294
295@control_command(

Callers

nothing calls this directly

Calls 6

rateFunction · 0.90
nokFunction · 0.85
okFunction · 0.85
errorMethod · 0.45
reset_rate_limitsMethod · 0.45
infoMethod · 0.45

Tested by

no test coverage detected