Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ActiveSupport classes in Sidekiq::Worker methods #2104

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
13 changes: 9 additions & 4 deletions lib/tapioca/dsl/compilers/sidekiq_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ module Compilers
# sig { params(customer_id: T.untyped).returns(String) }
# def self.perform_async(customer_id); end
#
# sig { params(interval: T.any(DateTime, Time), customer_id: T.untyped).returns(String) }
# sig do
# params(
# interval: T.any(DateTime, Time, ActiveSupport::TimeWithZone),
# customer_id: T.untyped
# ).returns(String)
# end
# def self.perform_at(interval, customer_id); end
#
# sig { params(interval: Numeric, customer_id: T.untyped).returns(String) }
# sig { params(interval: T.any(Numeric, ActiveSupport::Duration), customer_id: T.untyped).returns(String) }
# def self.perform_in(interval, customer_id); end
# end
# ~~~
Expand All @@ -54,11 +59,11 @@ def decorate
# accept a datetime, time, or numeric but we're typing them differently so they
# semantically make sense.
at_params = [
create_param("interval", type: "T.any(DateTime, Time)"),
create_param("interval", type: "T.any(DateTime, Time, ActiveSupport::TimeWithZone)"),
*async_params,
]
in_params = [
create_param("interval", type: "Numeric"),
create_param("interval", type: "T.any(Numeric, ActiveSupport::Duration)"),
*async_params,
]

Expand Down
4 changes: 2 additions & 2 deletions manual/compiler_sidekiqworker.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class NotifierWorker
sig { params(customer_id: T.untyped).returns(String) }
def self.perform_async(customer_id); end

sig { params(interval: T.any(DateTime, Time), customer_id: T.untyped).returns(String) }
sig { params(interval: T.any(DateTime, Time, ActiveSupport::TimeWithZone), customer_id: T.untyped).returns(String) }
def self.perform_at(interval, customer_id); end

sig { params(interval: Numeric, customer_id: T.untyped).returns(String) }
sig { params(interval: T.any(T.any(Numeric, ActiveSupport::Duration), ActiveSupport::Duration), customer_id: T.untyped).returns(String) }
def self.perform_in(interval, customer_id); end
end
~~~
4 changes: 2 additions & 2 deletions spec/tapioca/cli/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1158,10 +1158,10 @@ class << self
sig { params(foo: T.untyped, bar: T.untyped).returns(String) }
def perform_async(foo, bar); end

sig { params(interval: T.any(DateTime, Time), foo: T.untyped, bar: T.untyped).returns(String) }
sig { params(interval: T.any(DateTime, Time, ActiveSupport::TimeWithZone), foo: T.untyped, bar: T.untyped).returns(String) }
def perform_at(interval, foo, bar); end

sig { params(interval: Numeric, foo: T.untyped, bar: T.untyped).returns(String) }
sig { params(interval: T.any(Numeric, ActiveSupport::Duration), foo: T.untyped, bar: T.untyped).returns(String) }
def perform_in(interval, foo, bar); end
end

Expand Down
14 changes: 7 additions & 7 deletions spec/tapioca/dsl/compilers/sidekiq_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ class << self
sig { params(customer_id: T.untyped).returns(String) }
def perform_async(customer_id); end

sig { params(interval: T.any(DateTime, Time), customer_id: T.untyped).returns(String) }
sig { params(interval: T.any(DateTime, Time, ActiveSupport::TimeWithZone), customer_id: T.untyped).returns(String) }
def perform_at(interval, customer_id); end

sig { params(interval: Numeric, customer_id: T.untyped).returns(String) }
sig { params(interval: T.any(Numeric, ActiveSupport::Duration), customer_id: T.untyped).returns(String) }
def perform_in(interval, customer_id); end
end
end
Expand Down Expand Up @@ -100,10 +100,10 @@ class << self
sig { params(customer_id: ::Integer).returns(String) }
def perform_async(customer_id); end

sig { params(interval: T.any(DateTime, Time), customer_id: ::Integer).returns(String) }
sig { params(interval: T.any(DateTime, Time, ActiveSupport::TimeWithZone), customer_id: ::Integer).returns(String) }
def perform_at(interval, customer_id); end

sig { params(interval: Numeric, customer_id: ::Integer).returns(String) }
sig { params(interval: T.any(Numeric, ActiveSupport::Duration), customer_id: ::Integer).returns(String) }
def perform_in(interval, customer_id); end
end
end
Expand Down Expand Up @@ -133,10 +133,10 @@ class << self
sig { params(customer_id: T.untyped).returns(String) }
def perform_async(customer_id); end

sig { params(interval: T.any(DateTime, Time), customer_id: T.untyped).returns(String) }
sig { params(interval: T.any(DateTime, Time, ActiveSupport::TimeWithZone), customer_id: T.untyped).returns(String) }
def perform_at(interval, customer_id); end

sig { params(interval: Numeric, customer_id: T.untyped).returns(String) }
sig { params(interval: T.any(Numeric, ActiveSupport::Duration), customer_id: T.untyped).returns(String) }
def perform_in(interval, customer_id); end
end
end
Expand Down Expand Up @@ -171,7 +171,7 @@ class << self
sig { params(customer_id: T.untyped, other_id: T.untyped).returns(String) }
def perform_async(customer_id, other_id); end

sig { params(interval: Numeric, customer_id: T.untyped, other_id: T.untyped).returns(String) }
sig { params(interval: T.any(Numeric, ActiveSupport::Duration), customer_id: T.untyped, other_id: T.untyped).returns(String) }
def perform_in(interval, customer_id, other_id); end
end
end
Expand Down