-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.html
More file actions
43 lines (40 loc) · 34.5 KB
/
cli.html
File metadata and controls
43 lines (40 loc) · 34.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!doctype html>
<html lang="en-US" data-theme="light">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="generator" content="VuePress 2.0.0-rc.26" />
<meta name="theme" content="VuePress Theme Hope 2.0.0-rc.98" />
<style>
:root {
--vp-c-bg: #fff;
}
[data-theme="dark"] {
--vp-c-bg: #1b1b1f;
}
html,
body {
background: var(--vp-c-bg);
}
</style>
<script>
const userMode = localStorage.getItem("vuepress-theme-hope-scheme");
const systemDarkMode =
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches;
if (userMode === "dark" || (userMode !== "light" && systemDarkMode)) {
document.documentElement.setAttribute("data-theme", "dark");
}
</script>
<script type="application/ld+json">{"@context":"https://schema.org","@type":"Article","headline":"CLI","image":[""],"dateModified":"2025-11-14T14:19:40.000Z","author":[]}</script><meta property="og:url" content="https://taskiq-python.github.io/guide/cli.html"><meta property="og:site_name" content="Taskiq"><meta property="og:title" content="CLI"><meta property="og:description" content="CLI Core library comes with CLI program called taskiq, which is used to run different subcommands. By default taskiq is shipped with only two commands: worker and scheduler. You..."><meta property="og:type" content="article"><meta property="og:locale" content="en-US"><meta property="og:updated_time" content="2025-11-14T14:19:40.000Z"><meta property="article:modified_time" content="2025-11-14T14:19:40.000Z"><meta property="og:image" content="https://taskiq-python.github.io/logo.svg"><link rel="icon" href="/favicon.ico" type="image/x-icon"><link rel="icon" href="/favicon.svg" type="image/svg+xml"><link rel="apple-touch-icon" href="/favicon.png"><title>CLI | Taskiq</title><meta name="description" content="CLI Core library comes with CLI program called taskiq, which is used to run different subcommands. By default taskiq is shipped with only two commands: worker and scheduler. You...">
<link rel="preload" href="/assets/style-5mKr-C-v.css" as="style"><link rel="stylesheet" href="/assets/style-5mKr-C-v.css">
<link rel="modulepreload" href="/assets/app-jjAwnp1C.js"><link rel="modulepreload" href="/assets/cli.html-CnMDZED0.js"><link rel="modulepreload" href="/assets/plugin-vue_export-helper-DlAUqK2U.js">
<link rel="prefetch" href="/assets/index.html-CsAgJ-13.js" as="script"><link rel="prefetch" href="/assets/contrib.html-BZEqEwj-.js" as="script"><link rel="prefetch" href="/assets/index.html-DTzIgo1X.js" as="script"><link rel="prefetch" href="/assets/brokers.html-DaHldwxS.js" as="script"><link rel="prefetch" href="/assets/middlewares.html-v9d5K8-A.js" as="script"><link rel="prefetch" href="/assets/result-backends.html-D-vRlDHw.js" as="script"><link rel="prefetch" href="/assets/schedule-sources.html-BPBdcK7E.js" as="script"><link rel="prefetch" href="/assets/index.html-C5-jYX27.js" as="script"><link rel="prefetch" href="/assets/faststream.html-Me5ki3nB.js" as="script"><link rel="prefetch" href="/assets/taskiq-with-aiogram.html-Ck1xSZRJ.js" as="script"><link rel="prefetch" href="/assets/taskiq-with-aiohttp.html-D-yYlQ4o.js" as="script"><link rel="prefetch" href="/assets/taskiq-with-fastapi.html-BXvJ8FJZ.js" as="script"><link rel="prefetch" href="/assets/index.html-CElT2ZEv.js" as="script"><link rel="prefetch" href="/assets/broker.html-Bolg5nOu.js" as="script"><link rel="prefetch" href="/assets/cli.html-BdJ93hil.js" as="script"><link rel="prefetch" href="/assets/middleware.html-BHJwr1G1.js" as="script"><link rel="prefetch" href="/assets/result-backend.html-B_PpkMMD.js" as="script"><link rel="prefetch" href="/assets/schedule-sources.html-CYqJTL47.js" as="script"><link rel="prefetch" href="/assets/index.html-BgjLFYZQ.js" as="script"><link rel="prefetch" href="/assets/architecture-overview.html-DnsdLug5.js" as="script"><link rel="prefetch" href="/assets/dynamic-brokers.html-C7V4Xofu.js" as="script"><link rel="prefetch" href="/assets/getting-started.html-CIYxd8hb.js" as="script"><link rel="prefetch" href="/assets/message-format.html-DZVCut0-.js" as="script"><link rel="prefetch" href="/assets/scheduling-tasks.html-BJFKTUiT.js" as="script"><link rel="prefetch" href="/assets/state-and-deps.html-DBn18ICE.js" as="script"><link rel="prefetch" href="/assets/testing-taskiq.html-C-oBRYp_.js" as="script"><link rel="prefetch" href="/assets/404.html-CBBrf2yV.js" as="script"><link rel="prefetch" href="/assets/mermaid.esm.min-CR4_dSlb.js" as="script"><link rel="prefetch" href="/assets/photoswipe.esm-CKV1Bsxh.js" as="script">
</head>
<body>
<div id="app"><!--[--><!--[--><!--[--><span tabindex="-1"></span><a href="#main-content" class="vp-skip-link sr-only">Skip to main content</a><!--]--><!--[--><div class="theme-container external-link-icon pure has-toc" vp-container><!--[--><header id="navbar" class="vp-navbar" vp-navbar><div class="vp-navbar-start"><button type="button" class="vp-toggle-sidebar-button" title="Toggle Sidebar"><span class="icon"></span></button><!--[--><a class="route-link vp-brand" href="/" aria-label="Take me home"><img class="vp-nav-logo" src="/logo.svg" alt><!----><span class="vp-site-name hide-in-pad">Taskiq</span></a><!--]--></div><div class="vp-navbar-center"><!--[--><!----><!--]--></div><div class="vp-navbar-end"><!--[--><!----><div class="vp-nav-item vp-action"><a class="vp-action-link" href="https://github.com/taskiq-python/taskiq" target="_blank" rel="noopener noreferrer" aria-label="GitHub"><svg xmlns="http://www.w3.org/2000/svg" class="icon github-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="github icon" name="github" style="width:1.25rem;height:1.25rem;vertical-align:middle;"><path d="M511.957 21.333C241.024 21.333 21.333 240.981 21.333 512c0 216.832 140.544 400.725 335.574 465.664 24.49 4.395 32.256-10.07 32.256-23.083 0-11.69.256-44.245 0-85.205-136.448 29.61-164.736-64.64-164.736-64.64-22.315-56.704-54.4-71.765-54.4-71.765-44.587-30.464 3.285-29.824 3.285-29.824 49.195 3.413 75.179 50.517 75.179 50.517 43.776 75.008 114.816 53.333 142.762 40.79 4.523-31.66 17.152-53.377 31.19-65.537-108.971-12.458-223.488-54.485-223.488-242.602 0-53.547 19.114-97.323 50.517-131.67-5.035-12.33-21.93-62.293 4.779-129.834 0 0 41.258-13.184 134.912 50.346a469.803 469.803 0 0 1 122.88-16.554c41.642.213 83.626 5.632 122.88 16.554 93.653-63.488 134.784-50.346 134.784-50.346 26.752 67.541 9.898 117.504 4.864 129.834 31.402 34.347 50.474 78.123 50.474 131.67 0 188.586-114.73 230.016-224.042 242.09 17.578 15.232 33.578 44.672 33.578 90.454v135.85c0 13.142 7.936 27.606 32.854 22.87C862.25 912.597 1002.667 728.747 1002.667 512c0-271.019-219.648-490.667-490.71-490.667z"></path></svg></a></div><div class="vp-nav-item hide-in-mobile"><button type="button" class="vp-color-mode-switch" id="color-mode-switch"><svg xmlns="http://www.w3.org/2000/svg" class="icon auto-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="auto icon" name="auto" style="display:block;"><path d="M512 992C246.92 992 32 777.08 32 512S246.92 32 512 32s480 214.92 480 480-214.92 480-480 480zm0-840c-198.78 0-360 161.22-360 360 0 198.84 161.22 360 360 360s360-161.16 360-360c0-198.78-161.22-360-360-360zm0 660V212c165.72 0 300 134.34 300 300 0 165.72-134.28 300-300 300z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="dark icon" name="dark" style="display:none;"><path d="M524.8 938.667h-4.267a439.893 439.893 0 0 1-313.173-134.4 446.293 446.293 0 0 1-11.093-597.334A432.213 432.213 0 0 1 366.933 90.027a42.667 42.667 0 0 1 45.227 9.386 42.667 42.667 0 0 1 10.24 42.667 358.4 358.4 0 0 0 82.773 375.893 361.387 361.387 0 0 0 376.747 82.774 42.667 42.667 0 0 1 54.187 55.04 433.493 433.493 0 0 1-99.84 154.88 438.613 438.613 0 0 1-311.467 128z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="light icon" name="light" style="display:none;"><path d="M952 552h-80a40 40 0 0 1 0-80h80a40 40 0 0 1 0 80zM801.88 280.08a41 41 0 0 1-57.96-57.96l57.96-58a41.04 41.04 0 0 1 58 58l-58 57.96zM512 752a240 240 0 1 1 0-480 240 240 0 0 1 0 480zm0-560a40 40 0 0 1-40-40V72a40 40 0 0 1 80 0v80a40 40 0 0 1-40 40zm-289.88 88.08-58-57.96a41.04 41.04 0 0 1 58-58l57.96 58a41 41 0 0 1-57.96 57.96zM192 512a40 40 0 0 1-40 40H72a40 40 0 0 1 0-80h80a40 40 0 0 1 40 40zm30.12 231.92a41 41 0 0 1 57.96 57.96l-57.96 58a41.04 41.04 0 0 1-58-58l58-57.96zM512 832a40 40 0 0 1 40 40v80a40 40 0 0 1-80 0v-80a40 40 0 0 1 40-40zm289.88-88.08 58 57.96a41.04 41.04 0 0 1-58 58l-57.96-58a41 41 0 0 1 57.96-57.96z"></path></svg></button></div><form class="search-box" role="search"><input type="search" placeholder="Search" autocomplete="off" spellcheck="false" value><!----></form><!--]--><button type="button" class="vp-toggle-navbar-button" aria-label="Toggle Navbar" aria-expanded="false" aria-controls="nav-screen"><span><span class="vp-top"></span><span class="vp-middle"></span><span class="vp-bottom"></span></span></button></div></header><!----><!--]--><!----><div class="toggle-sidebar-wrapper"><span class="arrow start"></span></div><aside id="sidebar" class="vp-sidebar" vp-sidebar><!----><ul class="vp-sidebar-links"><li><a class="route-link auto-link vp-sidebar-link" href="/" aria-label="Task manager for asyncio"><!---->Task manager for asyncio<!----></a></li><li><section class="vp-sidebar-group"><button class="vp-sidebar-header clickable active" type="button"><!----><span class="vp-sidebar-title">Introduction</span><span class="vp-arrow down"></span></button><ul class="vp-sidebar-links"><li><a class="route-link auto-link vp-sidebar-link" href="/guide/" aria-label="Introduction"><!---->Introduction<!----></a></li><li><a class="route-link auto-link vp-sidebar-link" href="/guide/getting-started.html" aria-label="Getting started"><!---->Getting started<!----></a></li><li><a class="route-link auto-link vp-sidebar-link" href="/guide/architecture-overview.html" aria-label="Architecture overview"><!---->Architecture overview<!----></a></li><li><a class="route-link route-link-active auto-link vp-sidebar-link active" href="/guide/cli.html" aria-label="CLI"><!---->CLI<!----></a></li><li><a class="route-link auto-link vp-sidebar-link" href="/guide/state-and-deps.html" aria-label="State and Dependencies"><!---->State and Dependencies<!----></a></li><li><a class="route-link auto-link vp-sidebar-link" href="/guide/scheduling-tasks.html" aria-label="Scheduling tasks"><!---->Scheduling tasks<!----></a></li><li><a class="route-link auto-link vp-sidebar-link" href="/guide/dynamic-brokers.html" aria-label="Dynamic Environments"><!---->Dynamic Environments<!----></a></li><li><a class="route-link auto-link vp-sidebar-link" href="/guide/testing-taskiq.html" aria-label="Testing with taskiq"><!---->Testing with taskiq<!----></a></li><li><a class="route-link auto-link vp-sidebar-link" href="/guide/message-format.html" aria-label="Taskiq message format"><!---->Taskiq message format<!----></a></li></ul></section></li><li><section class="vp-sidebar-group"><button class="vp-sidebar-header clickable" type="button"><!----><span class="vp-sidebar-title">Framework integrations</span><span class="vp-arrow end"></span></button><!----></section></li><li><section class="vp-sidebar-group"><button class="vp-sidebar-header clickable" type="button"><!----><span class="vp-sidebar-title">Extending taskiq</span><span class="vp-arrow end"></span></button><!----></section></li><li><section class="vp-sidebar-group"><button class="vp-sidebar-header clickable" type="button"><!----><span class="vp-sidebar-title">Available components</span><span class="vp-arrow end"></span></button><!----></section></li><li><a class="route-link auto-link vp-sidebar-link" href="/contrib.html" aria-label="Contribution guide"><!---->Contribution guide<!----></a></li></ul><!----></aside><!--[--><!--[--><main id="main-content" class="vp-page"><!--[--><!----><!----><nav class="vp-breadcrumb disable"></nav><div class="vp-page-title"><h1><!---->CLI</h1><div class="page-info"><!----><!----><span class="page-date-info" aria-label="Writing Date"><svg xmlns="http://www.w3.org/2000/svg" class="icon calendar-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="calendar icon" name="calendar"><path d="M716.4 110.137c0-18.753-14.72-33.473-33.472-33.473-18.753 0-33.473 14.72-33.473 33.473v33.473h66.993v-33.473zm-334.87 0c0-18.753-14.72-33.473-33.473-33.473s-33.52 14.72-33.52 33.473v33.473h66.993v-33.473zm468.81 33.52H716.4v100.465c0 18.753-14.72 33.473-33.472 33.473a33.145 33.145 0 01-33.473-33.473V143.657H381.53v100.465c0 18.753-14.72 33.473-33.473 33.473a33.145 33.145 0 01-33.473-33.473V143.657H180.6A134.314 134.314 0 0046.66 277.595v535.756A134.314 134.314 0 00180.6 947.289h669.74a134.36 134.36 0 00133.94-133.938V277.595a134.314 134.314 0 00-133.94-133.938zm33.473 267.877H147.126a33.145 33.145 0 01-33.473-33.473c0-18.752 14.72-33.473 33.473-33.473h736.687c18.752 0 33.472 14.72 33.472 33.473a33.145 33.145 0 01-33.472 33.473z"></path></svg><span data-allow-mismatch="text">9/7/22</span><meta property="datePublished" content="2022-09-07T13:03:15.000Z"></span><!----><!----><!----><!----></div><hr></div><!----><div class="" vp-content><!----><div id="markdown-content"><h1 id="cli" tabindex="-1"><a class="header-anchor" href="#cli"><span>CLI</span></a></h1><p>Core library comes with CLI program called <code>taskiq</code>, which is used to run different subcommands.</p><p>By default taskiq is shipped with only two commands: <code>worker</code> and <code>scheduler</code>. You can search for more taskiq plugins using pypi. Some plugins may add new commands to taskiq.</p><h2 id="worker" tabindex="-1"><a class="header-anchor" href="#worker"><span>Worker</span></a></h2><p>To run worker process, you have to specify the broker you want to use and modules with defined tasks. Like this:</p><div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34;"><pre class="shiki shiki-themes one-light one-dark-pro vp-code"><code class="language-bash"><span class="line"><span style="--shiki-light:#4078F2;--shiki-dark:#61AFEF;">taskiq</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> worker</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> mybroker:broker_var</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> my_project.module1</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> my_project.module2</span></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="sync-function" tabindex="-1"><a class="header-anchor" href="#sync-function"><span>Sync function</span></a></h3><p>Taskiq can run synchronous functions. However, since it operates asynchronously, it executes them in a separate thread or process. By default, <strong>ThreadPoolExecutor</strong> is used. But if you're planning to use Taskiq for heavy computations, such as neural network model training or other CPU-intensive tasks, you may want to use <strong>ProcessPoolExecutor</strong> instead.</p><p>For more details on the differences between these two options, refer to the <a href="https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.Executor" target="_blank" rel="noopener noreferrer">Python docs on executors</a>.</p><p>As a rule of thumb:</p><ul><li>If you're using sync functions for IO then use <code>ThreadPoolExecutor</code>;</li><li>If you're using sync functions for CPU bound workloads then use <code>ProcessPoolExecutor</code>.</li></ul><p>By default taskiq uses <strong>threadpool</strong>. Here are some worker CLI options that can adjust its behavior:</p><ul><li><code>--use-process-pool</code> to switch to <code>ProcessPoolExecutor</code>;</li><li><code>--max-process-pool-processes</code> to manually specify worker processes;</li><li><code>--max-threadpool-threads</code> to configure maximum threads for <code>ThreadPoolExecutor</code> if it's the one being used.</li></ul><h3 id="auto-importing" tabindex="-1"><a class="header-anchor" href="#auto-importing"><span>Auto importing</span></a></h3><p>Enumerating all modules with tasks is not an option sometimes. That's why taskiq can auto-discover tasks in current directory recursively.</p><p>We have two options for this:</p><ul><li><code>--tasks-pattern</code> or <code>-tp</code>. It's a glob pattern of files to import. By default it is <code>**/tasks.py</code> which searches for all <code>tasks.py</code> files. May be specified multiple times.</li><li><code>--fs-discover</code> or <code>-fsd</code>. This option enables search of task files in current directory recursively, using the given pattern.</li></ul><h3 id="acknowledgements" tabindex="-1"><a class="header-anchor" href="#acknowledgements"><span>Acknowledgements</span></a></h3><p>The taskiq supports three types of acknowledgements:</p><ul><li><code>when_received</code> - task is acknowledged when it is <strong>received</strong> by the worker.</li><li><code>when_executed</code> - task is acknowledged right after it is <strong>executed</strong> by the worker.</li><li><code>when_saved</code> - task is acknowledged when the result of execution is saved in the result backend.</li></ul><p>This can be configured using <code>--ack-type</code> parameter. For example:</p><div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34;"><pre class="shiki shiki-themes one-light one-dark-pro vp-code"><code class="language-bash"><span class="line"><span style="--shiki-light:#4078F2;--shiki-dark:#61AFEF;">taskiq</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> worker</span><span style="--shiki-light:#986801;--shiki-dark:#D19A66;"> --ack-type</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> when_executed</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> mybroker:broker</span></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="type-casts" tabindex="-1"><a class="header-anchor" href="#type-casts"><span>Type casts</span></a></h3><p>One of features taskiq have is automatic type casts. For example you have a type-hinted task like this:</p><div class="language-python line-numbers-mode" data-highlighter="shiki" data-ext="python" style="--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34;"><pre class="shiki shiki-themes one-light one-dark-pro vp-code"><code class="language-python"><span class="line"><span style="--shiki-light:#A626A4;--shiki-dark:#C678DD;">async</span><span style="--shiki-light:#A626A4;--shiki-dark:#C678DD;"> def</span><span style="--shiki-light:#4078F2;--shiki-dark:#61AFEF;"> task</span><span style="--shiki-light:#383A42;--shiki-dark:#ABB2BF;">(</span><span style="--shiki-light:#986801;--shiki-light-font-style:inherit;--shiki-dark:#D19A66;--shiki-dark-font-style:italic;">val</span><span style="--shiki-light:#383A42;--shiki-dark:#ABB2BF;">:</span><span style="--shiki-light:#0184BC;--shiki-dark:#56B6C2;"> int</span><span style="--shiki-light:#383A42;--shiki-dark:#ABB2BF;">) -> </span><span style="--shiki-light:#0184BC;--shiki-dark:#56B6C2;">int</span><span style="--shiki-light:#383A42;--shiki-dark:#ABB2BF;">:</span></span>
<span class="line"><span style="--shiki-light:#A626A4;--shiki-dark:#C678DD;"> return</span><span style="--shiki-light:#383A42;--shiki-dark:#ABB2BF;"> val </span><span style="--shiki-light:#383A42;--shiki-dark:#56B6C2;">+</span><span style="--shiki-light:#986801;--shiki-dark:#D19A66;"> 1</span></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><p>If you'll call <code>task.kiq("2")</code> you'll get 3 as the returned value. Because we parse signatures of tasks and cast incoming parameters to target types. If type-cast fails you won't throw any error. It just leave the value as is. That functionality allows you to use pydantic models, or dataclasses as the input parameters.</p><p>To disable this pass the <code>--no-parse</code> option to the taskiq.</p><h3 id="hot-reload" tabindex="-1"><a class="header-anchor" href="#hot-reload"><span>Hot reload</span></a></h3><p>This is annoying to restart workers every time you modify tasks. That's why taskiq supports hot-reload. Reload is unavailable by default. To enable this feature install taskiq with <code>reload</code> extra.</p><div class="vp-tabs"><div class="vp-tabs-nav" role="tablist"><button type="button" class="vp-tab-nav active" role="tab" aria-controls="v-0" aria-selected="true">pip</button><button type="button" class="vp-tab-nav" role="tab" aria-controls="v-1" aria-selected="false">poetry</button><button type="button" class="vp-tab-nav" role="tab" aria-controls="v-2" aria-selected="false">uv</button></div><!--[--><div class="vp-tab active" id="v-0" role="tabpanel" aria-expanded="true"><div class="vp-tab-title">pip</div><!--[--><div class="language-bash" data-highlighter="shiki" data-ext="bash" style="--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34;"><pre class="shiki shiki-themes one-light one-dark-pro vp-code"><code class="language-bash"><span class="line"><span style="--shiki-light:#4078F2;--shiki-dark:#61AFEF;">pip</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> install</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> "taskiq[reload]"</span></span></code></pre></div><!--]--></div><div class="vp-tab" id="v-1" role="tabpanel" aria-expanded="false"><div class="vp-tab-title">poetry</div><!--[--><div class="language-bash" data-highlighter="shiki" data-ext="bash" style="--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34;"><pre class="shiki shiki-themes one-light one-dark-pro vp-code"><code class="language-bash"><span class="line"><span style="--shiki-light:#4078F2;--shiki-dark:#61AFEF;">poetry</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> add</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> taskiq</span><span style="--shiki-light:#986801;--shiki-dark:#D19A66;"> -E</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> reload</span></span></code></pre></div><!--]--></div><div class="vp-tab" id="v-2" role="tabpanel" aria-expanded="false"><div class="vp-tab-title">uv</div><!--[--><div class="language-bash" data-highlighter="shiki" data-ext="bash" style="--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34;"><pre class="shiki shiki-themes one-light one-dark-pro vp-code"><code class="language-bash"><span class="line"><span style="--shiki-light:#4078F2;--shiki-dark:#61AFEF;">uv</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> add</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> taskiq[reload]</span></span></code></pre></div><!--]--></div><!--]--></div><p>To enable this option simply pass the <code>--reload</code> or <code>-r</code> option to worker taskiq CLI.</p><p>You can set <code>--reload-dir</code> to specify directory to watch for changes. It can be specified multiple times if you need to watch multiple directories.</p><p>Also this option supports <code>.gitignore</code> files. If you have such file in your directory, it won't reload worker when you modify ignored files. To disable this functionality pass <code>--do-not-use-gitignore</code> option.</p><h3 id="graceful-reload-available-only-on-unix-systems" tabindex="-1"><a class="header-anchor" href="#graceful-reload-available-only-on-unix-systems"><span>Graceful reload (available only on Unix systems)</span></a></h3><p>To perform graceful reload, send <code>SIGHUP</code> signal to the main worker process. This action will reload all workers with new code. It's useful for deployment that requires zero downtime, but without using heavy orchestration tools like Kubernetes.</p><div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34;"><pre class="shiki shiki-themes one-light one-dark-pro vp-code"><code class="language-bash"><span class="line"><span style="--shiki-light:#4078F2;--shiki-dark:#61AFEF;">taskiq</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> worker</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> my_module:broker</span></span>
<span class="line"><span style="--shiki-light:#0184BC;--shiki-dark:#56B6C2;">kill</span><span style="--shiki-light:#986801;--shiki-dark:#D19A66;"> -HUP</span><span style="--shiki-light:#383A42;--shiki-dark:#ABB2BF;"> <</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;">main</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> pi</span><span style="--shiki-light:#383A42;--shiki-dark:#ABB2BF;">d></span></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="graceful-and-force-shutdowns" tabindex="-1"><a class="header-anchor" href="#graceful-and-force-shutdowns"><span>Graceful and force shutdowns</span></a></h3><p>If you send <code>SIGINT</code> or <code>SIGKILL</code> to the main process by pressing <kbd>Ctrl</kbd>+<kbd>C</kbd> or using the <code>kill</code> command, it will initiate the shutdown process. By default, it will stop fetching new messages immediately after receiving the signal but will wait for the completion of all currently executing tasks.</p><p>If you don't want to wait too long for tasks to complete each time you shut down the worker, you can either send termination signals three times to the main process to perform a hard kill or configure the <code>--wait-tasks-timeout</code> to set a hard time limit for shutting down.</p><div class="hint-container tip"><p class="hint-container-title">Cool tip</p><p>The number of signals before a hard kill can be configured with the <code>--hardkill-count</code> CLI argument.</p></div><h3 id="other-parameters" tabindex="-1"><a class="header-anchor" href="#other-parameters"><span>Other parameters</span></a></h3><ul><li><code>--app-dir</code> - Path to application directory. This path will be used to import tasks modules. If not specified, current working directory will be used.</li><li><code>--workers</code> - Number of worker child processes (default: 2).</li><li><code>--no-configure-logging</code> - disables default logging configuration for workers.</li><li><code>--log-level</code> is used to set a log level (default <code>INFO</code>).</li><li><code>--log-format</code> is used to set a log format (default <code>%(asctime)s][%(name)s][%(levelname)-7s][%(processName)s] %(message)s</code>).</li><li><code>--max-async-tasks</code> - maximum number of simultaneously running async tasks.</li><li><code>--max-prefetch</code> - number of tasks to be prefetched before execution. (Useful for systems with high message rates, but brokers should support acknowledgements).</li><li><code>--max-threadpool-threads</code> - number of threads for sync function execution.</li><li><code>--no-propagate-errors</code> - if this parameter is enabled, exceptions won't be thrown in generator dependencies.</li><li><code>--receiver</code> - python path to custom receiver class.</li><li><code>--receiver_arg</code> - custom args for receiver.</li><li><code>--ack-type</code> - Type of acknowledgement. This parameter is used to set when to acknowledge the task. Possible values are <code>when_received</code>, <code>when_executed</code>, <code>when_saved</code>. Default is <code>when_saved</code>.</li><li><code>--max-tasks-per-child</code> - maximum number of tasks to be executed by a single worker process before restart.</li><li><code>--max-fails</code> - Maximum number of child process exits.</li><li><code>--shutdown-timeout</code> - maximum amount of time for graceful broker's shutdown in seconds (default 5).</li><li><code>--wait-tasks-timeout</code> - if cannot read new messages from the broker or maximum number of tasks is reached, worker will wait for all current tasks to finish. This parameter sets the maximum amount of time to wait until shutdown.</li><li><code>--hardkill-count</code> - Number of termination signals to the main process before performing a hardkill.</li></ul><h2 id="scheduler" tabindex="-1"><a class="header-anchor" href="#scheduler"><span>Scheduler</span></a></h2><p>Scheduler is used to schedule tasks as described in <a class="route-link" href="/guide/scheduling-tasks.html">Scheduling tasks</a> section.</p><p>To run it simply run</p><div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34;"><pre class="shiki shiki-themes one-light one-dark-pro vp-code"><code class="language-bash"><span class="line"><span style="--shiki-light:#4078F2;--shiki-dark:#61AFEF;">taskiq</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> scheduler</span><span style="--shiki-light:#383A42;--shiki-dark:#ABB2BF;"> <</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;">path</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> to</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> schedule</span><span style="--shiki-light:#383A42;--shiki-dark:#ABB2BF;">r> [optional </span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;">module</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> to</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> import]...</span></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><p>For example</p><div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34;"><pre class="shiki shiki-themes one-light one-dark-pro vp-code"><code class="language-bash"><span class="line"><span style="--shiki-light:#4078F2;--shiki-dark:#61AFEF;">taskiq</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> scheduler</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> my_project.broker:scheduler</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> my_project.module1</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> my_project.module2</span></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="parameters" tabindex="-1"><a class="header-anchor" href="#parameters"><span>Parameters</span></a></h3><p>Path to scheduler is the only required argument.</p><ul><li><code>--app-dir</code> - Path to application directory. This path will be used to import tasks modules. If not specified, current working directory will be used.</li><li><code>--tasks-pattern</code> or <code>-tp</code>. It's a glob pattern of files to import. By default it is <code>**/tasks.py</code> which searches for all <code>tasks.py</code> files. May be specified multiple times.</li><li><code>--fs-discover</code> or <code>-fsd</code>. This option enables search of task files in current directory recursively, using the given pattern.</li><li><code>--no-configure-logging</code> - use this parameter if your application configures custom logging.</li><li><code>--log-level</code> is used to set a log level (default <code>INFO</code>).</li><li><code>--skip-first-run</code> - skip first run of scheduler. This option skips running tasks immediately after scheduler start.</li><li><code>--update-interval</code> - interval in seconds to check for new tasks. By default scheduler will check for new scheduled tasks every first second of the minute.</li></ul></div><!----><!----><!----></div><footer class="vp-page-meta"><div class="vp-meta-item edit-link"><a class="auto-link external-link vp-meta-label" href="https://github.com/taskiq-python/taskiq/edit/master/docs/guide/cli.md" aria-label="Edit this page" rel="noopener noreferrer" target="_blank"><!--[--><svg xmlns="http://www.w3.org/2000/svg" class="icon edit-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="edit icon" name="edit"><path d="M430.818 653.65a60.46 60.46 0 0 1-50.96-93.281l71.69-114.012 7.773-10.365L816.038 80.138A60.46 60.46 0 0 1 859.225 62a60.46 60.46 0 0 1 43.186 18.138l43.186 43.186a60.46 60.46 0 0 1 0 86.373L588.879 565.55l-8.637 8.637-117.466 68.234a60.46 60.46 0 0 1-31.958 11.229z"></path><path d="M728.802 962H252.891A190.883 190.883 0 0 1 62.008 771.98V296.934a190.883 190.883 0 0 1 190.883-192.61h267.754a60.46 60.46 0 0 1 0 120.92H252.891a69.962 69.962 0 0 0-69.098 69.099V771.98a69.962 69.962 0 0 0 69.098 69.098h475.911A69.962 69.962 0 0 0 797.9 771.98V503.363a60.46 60.46 0 1 1 120.922 0V771.98A190.883 190.883 0 0 1 728.802 962z"></path></svg><!--]-->Edit this page<!----></a></div><div class="vp-meta-item git-info"><div class="update-time"><span class="vp-meta-label">Last Updated: </span><time class="vp-meta-info" datetime="2025-11-14T14:19:40.000Z" data-allow-mismatch>11/14/25, 2:19 PM</time></div><div class="contributors"><span class="vp-meta-label">Contributors: </span><!--[--><!--[--><span class="vp-meta-info" title="email: win10@list.ru">Pavel Kirilin</span>,<!--]--><!--[--><span class="vp-meta-info" title="email: mister-hope@outlook.com">Mr.Hope</span>,<!--]--><!--[--><span class="vp-meta-info" title="email: jan.musilek@nic.cz">Jan Musílek</span>,<!--]--><!--[--><span class="vp-meta-info" title="email: 20261699+TheTechromancer@users.noreply.github.com">TheTechromancer</span>,<!--]--><!--[--><span class="vp-meta-info" title="email: anfimov@tochka.com">Dmitrii Anfimov</span><!--]--><!--]--></div></div></footer><nav class="vp-page-nav"><a class="route-link auto-link prev" href="/guide/architecture-overview.html" aria-label="Architecture overview"><div class="hint"><span class="arrow start"></span>Prev</div><div class="link"><!---->Architecture overview</div></a><a class="route-link auto-link next" href="/guide/state-and-deps.html" aria-label="State and Dependencies"><div class="hint">Next<span class="arrow end"></span></div><div class="link">State and Dependencies<!----></div></a></nav><!----><!----><!--]--></main><!--]--><!--]--><!----></div><!--]--><!--]--><!--[--><!----><!--[--><!--]--><!--]--><!--]--></div>
<script type="module" src="/assets/app-jjAwnp1C.js" defer></script>
</body>
</html>