Skip to content

Instantly share code, notes, and snippets.

View Irostovsky's full-sized avatar

Ivan Rostovsky Irostovsky

View GitHub Profile
class FooPresenter
include Draper::Decoratable
attr_accessor :user
def initialize(user)
@user = user
end
def name
user.name
@Irostovsky
Irostovsky / timer.rb
Created July 19, 2018 09:26
Bench timer
# frozen_string_literal: true
module Utils
class Timer
def self.call(name)
t = Time.zone.now
result = yield
time = ((Time.zone.now - t).to_d * 1000).to_i
p "++++++++++ #{name}: #{time}ms"
{ result: result, time: time }
@Irostovsky
Irostovsky / show_sql_in_shell
Created May 27, 2019 11:54
python and django tricks
import logging
log = logging.getLogger('django.db.backends')
log.setLevel(logging.DEBUG)
log.addHandler(logging.StreamHandler())
@Irostovsky
Irostovsky / celery-ack-late-idempotency-audit.md
Created February 5, 2026 08:35
Celery ack_late idempotency audit - all tasks analysis

Celery ack_late Idempotency Audit

Context

Celery 5.x has a known bug: without ack_late, the prefetch count is not enforced correctly. Workers grab all messages from the queue into an internal buffer, acking them immediately on receipt. RabbitMQ then shows 0 "Ready" messages, and autoscalers have nothing to trigger on.

With ack_late enabled, the prefetch limit works correctly: each worker holds at most prefetch_multiplier * concurrency (= 2 in our case) unacked messages, and the rest stay as "Ready" in the queue.

Trade-off

"""
Create missing ReservationExtraFee records for BOOKING reservations affected by PCPv2
(created between 2026-03-24 13:00 UTC and 2026-04-01 09:54 UTC) and generate
invoices for those outside the automatic creation window.
Accounts for Booking.com fee renaming:
- resort_fee, destination_fee, etc. may arrive as "service_charge"
- tourism_fee is mapped into taxe_sejour (city tax)
Usage: