Class: SolidusBactracs::Shipment::PendingApiSyncQuery

Inherits:
Object
  • Object
show all
Defined in:
app/queries/solidus_bactracs/shipment/pending_api_sync_query.rb

Constant Summary collapse

SQLITE_CONDITION =
<<~SQL.squish
  (
    spree_shipments.bactracs_synced_at IS NULL
  ) AND ((JULIANDAY(CURRENT_TIMESTAMP) - JULIANDAY(spree_orders.updated_at)) * 86400.0) < :threshold
SQL
POSTGRES_CONDITION =
<<~SQL.squish
  (
    spree_shipments.bactracs_synced_at IS NULL
  ) AND (EXTRACT(EPOCH FROM (CURRENT_TIMESTAMP - spree_orders.updated_at))) < :threshold
SQL
MYSQL2_CONDITION =
<<~SQL.squish
  (
    spree_shipments.bactracs_synced_at IS NULL
  ) AND (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(spree_orders.updated_at)) < :threshold
SQL

Class Method Summary collapse

Class Method Details

.apply(scope) ⇒ Object



25
26
27
28
29
30
# File 'app/queries/solidus_bactracs/shipment/pending_api_sync_query.rb', line 25

def apply(scope)
  scope
    .joins(:order)
    .merge(::Spree::Order.complete)
    .where(condition_for_adapter, threshold: SolidusBactracs.config.api_sync_threshold / 1.second)
end