Skip to content

Instantly share code, notes, and snippets.

@danielmfern
Last active January 22, 2026 16:15
Show Gist options
  • Select an option

  • Save danielmfern/cc70211ff784bab00a7a32bfe3aa1662 to your computer and use it in GitHub Desktop.

Select an option

Save danielmfern/cc70211ff784bab00a7a32bfe3aa1662 to your computer and use it in GitHub Desktop.
# process_editables.rb
# Lambda tiene concurrencia de 20 + SQS queue, no necesita rate limiting manual
Current.account = Account.find 9
Current.user = User.first
shot_ids = Flow::ShotImage
.joins(shot: { task: :card })
.where(flag: 'e1', extension: 'jpg', step: 'final')
.merge(Flow::Card.where(campaign: 'V2026'))
.distinct
.pluck(:flow_shot_id)
shots = Flow::Shot.where(editable_id: shot_ids)
Rails.logger.info("Total shots to process: #{shots.count}")
processed_count = 0
error_count = 0
skipped_count = 0
shots.find_each(batch_size: 100) do |shot|
begin
filename = shot.download_filename('retouch').gsub(shot.id.to_s, shot.editable_id.to_s)
if filename.start_with?('2')
skipped_count += 1
next
end
actions = Flow::AutomaticActions::DetectionService.new(filename).execute
action_code = 'background_remove_jpg'
output_filename = actions.find { |a| a['action'] == action_code }['output_filename']
action_execution = Flow::ActionExecution.create!(
filename:,
output_filename:,
blob_id: shot.file.signed_id,
action_code:,
user_action_id: '-999999', # Generar un nuevo user_action_id por "batch"
request_params: { step: 'final' }
)
processed_count += 1
Rails.logger.info("SUCCESS: #{filename} (#{processed_count} processed)") if processed_count % 10 == 0
rescue StandardError => e
error_count += 1
Rails.logger.error("ERROR shot #{shot.id}: #{e.message}")
end
end
Rails.logger.info("Script completed - Processed: #{processed_count}, Errors: #{error_count}, Skipped: #{skipped_count}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment