require "sidekiq"require "sidekiq/api"connection_url = ENV['UPSTASH_REDIS_LINK']Sidekiq.configure_client do |config| config.redis = {url: connection_url}endSidekiq.configure_server do |config| config.redis = {url: connection_url}endclass EmailService include Sidekiq::Worker def perform(id, type) # Logic goes here. Let's assume sending email by printing to console. puts "Emailed to: " + id + ": " + "'Congrats on " + type + " plan.'" endenddef updateEmail(id, newType) jobFound = false a = Sidekiq::ScheduledSet.new a.each do |job| if job.args[0] == id job.delete jobFound = true end end if jobFound EmailService.perform_async(id, ("starting using our service and upgrading it to " + newType)) else EmailService.perform_async(id, ("upgrading to " + newType)) endenddef sendEmail(id, type) case type when "free" # if free, delay for 10 seconds. EmailService.perform_in("10", id, "free") when "paid" # if paid, delay for 5 seconds. EmailService.perform_in("5", id, "paid") when "enterprise" # if enterprise, immediately queue. EmailService.perform_async(id, "enterprise") when "enterprise10k" EmailService.perform_async(id, "enterprise10k") else puts "Only plans are: `free`, `paid` and `enterprise`" endenddef clearSchedules() Sidekiq::ScheduledSet.new.clear Sidekiq::Queue.new.clearend
Sidekiq accesses Redis regularly, even when there is no queue activity. This can incur extra costs because Upstash charges per request on the Pay-As-You-Go plan. With the introduction of our Fixed plans, we recommend switching to a Fixed plan to avoid increased command count and high costs in Sidekiq use cases.