debshots/lib/tasks
Christoph Haas c5cd77e9ee Stop concurrent imports from racing on package names
Production imports kept aborting with
ActiveRecord::RecordNotUnique on packages_name_key and - on
environments that never got the constraint - silently created
duplicate packages. Root cause: overlapping update_from_deb_repos
runs (scheduled + manual) both do find-by-name then insert; whichever
wins the race aborts the whole run, whichever loses gets a
duplicate if the constraint was missing.

Three things so the mechanism stops being the problem:

- An advisory lock serializes update_from_deb_repos runs. A second
  run that finds the lock held simply skips with a warning instead
  of racing the first one. The lock is session-scoped, so it is
  released automatically when the process exits.
- A per-package rescue for ActiveRecord::RecordNotUnique. If a
  create still races (e.g. a package being created by a web upload),
  the package is re-fetched and updated instead of aborting the run.
- A real migration for packages_name_key, which previously only
  existed where it had been added by hand. From now on db:migrate
  creates it everywhere, new databases included.

Also verified with a reproduction: a single sequential run of the
deployed importer against a fresh database (both architectures,
~54k packages) creates zero duplicates.
2026-09-04 21:57:35 +02:00
..
.keep Blank rails 4.0 project started 2013-07-27 00:19:29 +02:00
accesslog2visits.rake Speed improvement in updating database 2016-08-11 11:20:37 +02:00
add_admin.rake add Rake task to create admin users 2025-05-21 00:23:51 +02:00
import_debian.rake Stop concurrent imports from racing on package names 2026-09-04 21:57:35 +02:00
purge_old_logs.rake added job to purge old log files 2025-06-23 00:46:32 +02:00
remove_broken_screenshots.rake Rake task fixed for Shring 2021-02-25 00:14:08 +01:00
remove_image_duplicates.rake Using created_at instead of legacy 'uploaddatetime' field 2016-03-04 15:41:50 +01:00
shrine_recreate_derivatives.rake Added rake task to create derivates after migration 2020-11-12 22:28:29 +01:00
vectorize_packages.rake Log the failing SQL statement in vectorization task 2026-08-23 00:31:04 +02:00