Skip to content

chore: Adapt autorate calculators for Manul API#91

Closed
dapi wants to merge 19 commits intofeature/69-position-aware-autoratefrom
chore/89-adapt-autorate-calculators-manul
Closed

chore: Adapt autorate calculators for Manul API#91
dapi wants to merge 19 commits intofeature/69-position-aware-autoratefrom
chore/89-adapt-autorate-calculators-manul

Conversation

@dapi
Copy link
Copy Markdown

@dapi dapi commented Jan 20, 2026

Изменения относительно оригинального PR #71

Адаптация для текущего master:

  • external_rates использует Gera.manul_client&.top_exchangers() вместо BestChange::Service
  • perform_asyncperform_later (ActiveJob)
  • WorkerJob
  • Добавлен метод bestchange_key
  • Добавлены manul_client и enable_direction_rate_history_intervals в конфиг
  • Калькуляторы адаптированы для формата Manul API ({'rate' => '...', 'changer_id' => ...})

🤖 Generated with Claude Code

dapi and others added 19 commits December 1, 2025 14:28
- Replace all Sidekiq workers with ActiveJob jobs
- Convert RatesWorker concern to RatesJob concern
- Use limits_concurrency for Solid Queue instead of sidekiq-unique-jobs
- Replace perform_async with perform_later
- Update all model and controller references
- Create new job spec files, remove old worker specs

Jobs converted:
- DirectionsRatesJob
- CurrencyRatesJob
- ExternalRatesBatchJob
- ExternalRateSaverJob
- ExchangeRateUpdaterJob
- CreateHistoryIntervalsJob
- CbrRatesJob, CbrAvgRatesJob
- BinanceRatesJob, ExmoRatesJob, BybitRatesJob
- BitfinexRatesJob, CryptomusRatesJob
- GarantexioRatesJob, FfFixedRatesJob, FfFloatRatesJob

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Solid Queue passes the job instance to the key lambda, but our lambdas
expected no arguments. Changed from `-> { key }` to `->(_job) { key }`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Replace sidekiq gem with solid_queue in gemspec
- Update lib/gera.rb to require solid_queue instead of sidekiq
- Remove sidekiq/testing from spec_helper, use ActiveJob test adapter
- Remove incorrect SolidQueue::Job::Concurrency include (engine auto-includes)

SolidQueue's engine automatically includes ActiveJob::ConcurrencyControls
which provides the limits_concurrency method for concurrency control.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Major version bump due to migration from Sidekiq to ActiveJob.

Breaking changes:
- All workers renamed to jobs (e.g., ExmoRatesWorker → ExmoRatesJob)
- Sidekiq dependency replaced with solid_queue
- Worker concerns renamed to job concerns (RatesWorker → RatesJob)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Update log message in ExchangeRate#update_finite_rate! to reflect
the ActiveJob method name after Sidekiq migration.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Replace `open(url).read` with `Net::HTTP.get(uri)` in ExmoFetcher
- Replace `open uri` with `URI.open(uri)` in CbrRatesJob
- Centralize require 'open-uri' and 'net/http' in lib/gera.rb
- Remove duplicate requires from individual files
- Update ExmoFetcher spec to mock Net::HTTP.get

In Ruby 3.0+, Kernel#open with URI strings requires open-uri and
explicit URI.open call. This change prevents ENOENT errors when
fetching external rate APIs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…ency

Refactored both fetchers to use RestClient directly instead of inheriting
from PaymentServices::Base::Client (which is defined in the host app).

Fixes #1650

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Change lambda from ->(_job) to ->(*) in all jobs to handle
recurring tasks without arguments. SolidQueue calls the key lambda
with *arguments (job arguments), and for recurring tasks without
args: in config/recurring.yml, this passes 0 arguments.

Bump version to 1.2.0

Fixes: alfagen/mercury#1651

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Optimization for mercury issue #1691:
- DirectionRate contains pre-calculated rate_percent (commission)
- ExchangeRate contains is_enabled?, auto_rate? (direction settings)
- Instead of calling er.final_rate_percents (4 DB queries each time)
  use dr.rate_percent (already saved, 0 queries)
- includes loads all exchange_rates in 1 additional query

Before: N×M × 4 queries when displaying rates matrix
After: 2 queries (direction_rates + exchange_rates)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…ry-includes

Add includes(:exchange_rate) to DirectionRatesRepository#build_matrix
When currency rate cannot be calculated for a pair, log a warning
instead of raising an error and notifying Bugsnag. This is expected
behavior when rate data is unavailable from sources.

- Replace raise Error with logger.warn and early return
- Change RateSource::RateNotFound from error to warn level
- Remove unused Error class
- Add tests for graceful handling

Fixes alfagen/mercury#1708

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Fix: graceful handling для отсутствующих курсов валют
…ivejob

Migrate from Sidekiq to ActiveJob
Allow disabling direction_rate_history_intervals creation to save disk space
(~42GB on production). The table is only used for admin charts.

- Add enable_direction_rate_history_intervals config (default: true)
- Skip saving direction_rate_history_intervals when disabled
- Add helper method for controller to check status
- Show warning banner in view when collection is disabled

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
…istory-intervals

Add enable_direction_rate_history_intervals config option
Adapts PR #71 (position-aware autorate) for current master:
- Add AutorateCalculators::Legacy and PositionAware with Strategy pattern
- Use Manul API instead of BestChange::Service for external rates
- Use ActiveJob (perform_later) instead of Sidekiq (perform_async)
- Add calculator_type column to exchange_rates for selecting algorithm
- Add our_exchanger_id and anomaly_threshold_percent config options

The PositionAware calculator prevents "jumping over" positions above
the target range, with adaptive GAP and anomaly protection.

Closes #69

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant