31 Commits
Author SHA1 Message Date
Davide Silvestri f5bc919473 feat(celery): make every task work on a threads worker, and use one in dev (#6926)
* chore(dev): run one threads Celery worker with beat in dev

The Docker and native dev stacks start a single Celery worker for every
queue, with redbeat embedded, instead of a worker, an export worker and a
beat process. It uses a new ThreadsPool that sends worker_process_init, so
telemetry and the lazy import check still run under the threads pool.

* fix(ws): stop closing every event loop's Redis pools after a broadcast

send_messages_to_channel_group called channel_layer.close_pools(), which
closes the pools of every event loop, including the ones other worker
threads are still sending with. Under the threads pool about a third of
broadcasts failed with "attached to a different loop" and some hung.
channels_redis now closes a loop's pools itself when that loop closes.

* fix(telemetry): keep Celery trace context per thread on threads workers

The Celery instrumentation keys a running task's span, context token and start
time by the task's id. A task replaced with self.replace(), like every
automation node, keeps its id, and on a threads worker the replacement can
start in another thread before the original ends. The original then ended the
replacement's span and detached its context from the wrong thread, logging
"Failed to detach context" and leaving its own context on the thread. That
state is now kept per thread.

* feat(celery): enforce soft and hard time limits in ThreadsPool

Celery's own threads pool ignores soft_time_limit and time_limit, so on a
threads worker tasks that rely on them would run on. ThreadsPool now raises
the limit in the task's thread, only while that task runs, so a limit never
reaches the next task of the thread. EMAIL_TIMEOUT stops a silent SMTP server
from blocking a worker thread forever.

* fix(chat-runs): cancel a run that keeps going after its deadline

The deadline only asks a run to stop. A run whose tools or provider call
ignore that request now gets 60 more seconds, is then cancelled, and is saved
as timed out. Celery's limit moves after that, so the run's own stop always
comes first. On a threads worker this is the only way to end it, because a
time limit can't reach a thread waiting inside async_to_sync.

* fix(premium): share one capped thread pool across AI field generations

Each generation started its own pool of
BASEROW_AI_FIELD_MAX_CONCURRENT_GENERATIONS threads, so a threads worker
running several jobs multiplied the threads and model calls. All generations
in a process now share one pool of that size. A prefork process runs one job
at a time, so nothing changes there.

* feat(celery): cancel queries at the hard limit and report overdue tasks

ThreadsPool checks every running task's time limits from one watchdog thread,
like the prefork pool's timeout handler, instead of starting timer threads
for each task. At the hard limit it also cancels the query the task's thread
is running, which the limit's exception can't interrupt.

A thread can't be killed, so a task still running 60 seconds after its hard
limit is reported to Sentry instead. Every limit reached is counted in
baserow.celery.task.time_limit, per task and limit.

* fix(airtable): time out requests to Airtable

Two Airtable import requests had no timeout, so a server that stopped
answering held the import, and on a threads worker its thread, forever. All
Airtable requests now use the same 3 minute read timeout.

* fix(celery): load sentry_sdk only when reporting an overdue task

The overdue report imported sentry_sdk at the top of baserow.config.celery,
which every process imports, so it was loaded even with Sentry off.

* chore: add a changelog entry for the Celery task timeouts

* fix(celery): raise threads pool time limits at the task's next query

An exception raised into a thread from outside can land right after a lock
is taken and before the code that releases it, leaving the lock held for
every thread of the worker. The pool now marks a reached limit and the
task's own next query raises it, once, through a connection execute
wrapper. The hard limit still cancels the running query, and raises
TimeLimitExceeded whatever the soft limit is. Limits end before Celery's
success callback runs. Savepoint queries are never interrupted, through
a helper shared with the periodic field update deadline.

* fix(celery): apply the worker default time limits on the threads pool

Celery passes CELERY_TASK_SOFT_TIME_LIMIT and CELERY_TASK_TIME_LIMIT to the pool and None per task when a task sets no limit. The prefork pool falls back to the pool's values; the threads pool now does too.

* fix(celery): keep threads pool time limits until running tasks end

The watchdog stopped before on_stop waited for the running tasks, so a task passing its limit during a warm shutdown was never stopped or reported.

* chore: name the emails the SMTP timeout covers in the changelog

EMAIL_TIMEOUT applies to the instance's own emails only. Automation and builder SMTP steps already time out after 30 seconds.

* chore(dev): drop dev.sh tabs for the removed Celery workers

The export and beat services are disabled, so attaching to them made the script exit before opening the remaining tabs.

* test(celery): cover thread time limits and savepoint rollback

* fix(ai): use one generation slot for nonpositive limits

* fix(chat): warn that an action may finish after a reply times out

* docs(celery): explain which timeout guarantees require prefork

* docs(celery): record the threads pool decision and task contract

* fix(chat): keep the worker slot until started tools finish

* fix(chat): warn visitors about repeating a timed-out request

* docs(chat): clarify when the stop grace period begins
2026-12-03 09:39:52 +01:00
Jérémie Pardou d109762e88 Improve backend error feedbacks 2025-07-09 16:19:04 +02:00
Davide Silvestri 4db2c78d99 Resolve "Remove PG11 images creation from the CI" 2025-01-27 14:47:52 +00:00
Jérémie Pardou 63117027a6 Add builder first e2e tests 2024-11-14 12:30:42 +00:00
Eimantas Stonys 24a4708323 Upgrade to PostgreSQL 15 2024-04-03 08:04:17 +00:00
Nigel Gott aa80a2022f Make tests more reliable in parallel + add hooks in dev.sh to allow for custom... 2023-06-27 09:08:07 +00:00
Peter Evans f628ad96ae Resolve "Ensure that e2e tests have staff users post_migrate." 2023-03-14 15:08:55 +00:00
Nigel Gott 2bbb22be2f Resolve "Export useful opentelemetry metrics." 2023-03-03 16:58:45 +00:00
Peter Evans 0355d3c10a Applying a macOS specific patch to make e2e testing work 2023-03-02 13:52:59 +00:00
Petr Stribny fda53607c7 CI for e2e tests 2023-02-27 16:05:07 +00:00
Jrmi 1ffcd490c5 Add management command to load test data 2023-01-04 11:51:28 +00:00
Nigel Gott 02acea9778 Various self-hosting QOL fixes 2022-07-01 15:43:28 +00:00
Nigel Gott f7de18ff7c Merge branch '1041-add-check-of-baserow_public_url-and-public_backend_url-to-make-sure-they-are-valid' into 'develop'
Resolve "Add check of BASEROW_PUBLIC_URL and PUBLIC_BACKEND_URL to make sure they are valid"

Closes #1041

See merge request bramw/baserow!833
2022-07-01 06:51:56 +00:00
Nigel Gott 32d40cc54d Resolve "Add check of BASEROW_PUBLIC_URL and PUBLIC_BACKEND_URL to make sure they are valid" 2022-07-01 06:51:55 +00:00
Nigel Gott 911382d84f Add an all-in-one dev mode. 2022-06-30 17:43:32 +01:00
Nigel Gott cb21714883 Resolve "Sync templates on startup in an async job" 2022-05-27 14:44:54 +00:00
Davide Silvestri be813b0f54 Add to dev.sh the support for KDE konsole 2022-04-05 15:42:13 +00:00
Nigel Gott 7f8021abab Switch dev mode to how it worked before, fix celery beat throwing errors on... 2022-03-03 14:12:20 +00:00
Nigel Gott c16ece456d Fix install on ubuntu upgrade to docker guide, make .dev.sh supply sensible... 2022-03-02 12:12:04 +00:00
Nigel Gott f6361ee3bd Various docker ci fixes 2022-03-01 21:49:49 +00:00
Nigel Gott 04f1d7f82f Heroku fixes, updated docs, fix build. 2022-03-01 15:22:47 +00:00
Nigel Gott 2ee7ab56f7 Fix various bugs 2022-02-28 17:00:01 +00:00
Nigel Gott 13bb140618 Add all-in-one image used as a base by cloudron/heroku.
Signed-off-by: Nigel Gott <nigel@baserow.io>
2022-02-28 13:56:55 +00:00
Nigel Gott 56549afd1c pre-compile mjml email templates and delete runtime mjml-tcpserver for enhanced security, reduced architectural complexity and faster/simpler email setup. 2022-02-28 13:21:17 +00:00
Nigel Gott 241958a8ab Setup Baserow to build its images in CI for Gitlab. 2022-02-28 13:19:00 +00:00
Erwan Daubert 0128d06c47 Change the way variables are used (no substitution as empty value will be the default result) 2021-12-15 12:26:02 +00:00
Nigel Gott 88a5322c88 Resolve "Remove Container Names and allow Media URL to be configurable" 2021-10-08 15:18:24 +00:00
Nigel Gott a943716dde Final formula MR 2021-10-05 11:31:44 +00:00
Nigel Gott af96c3d730 Various docker fixes:
- Dont use a named volume to store node_modules in the dev
env to always get a fresh image based node_modules
- Fix the PUBLIC_WEB_FRONTEND_URL mis config in the docker-compose file
- Update docs for publicly exposing baserow
- Fix bad link in docs
2021-07-29 10:11:55 +01:00
Nigel Gott b724d72294 Resolve "Export table/view data to CSV/XML/JSON" 2021-06-01 09:30:30 +00:00
Nigel Gott ee7314b64d Resolve "Make it easier to run production version on local machine" 2021-04-22 11:51:15 +00:00