Class: PandaPal::OrganizationConcerns::TaskScheduling::ScheduledTaskExecutor

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/models/panda_pal/organization_concerns/task_scheduling.rb

Instance Method Summary collapse

Instance Method Details

#perform(org_name, task_key) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'app/models/panda_pal/organization_concerns/task_scheduling.rb', line 197

def perform(org_name, task_key)
  org = Organization.find_by!(name: org_name)
  task = Organization._schedule_descriptors[task_key]
  worker = task[:worker]

  Apartment::Tenant.switch(org.name) do
    if worker.is_a?(Proc)
      return org.instance_exec(&worker)
    elsif worker.is_a?(Symbol)
      return org.send(worker)
    elsif worker.is_a?(String)
      worker = worker.constantize
    end

    if worker.is_a?(Class)
      if worker.respond_to?(:perform_async)
        worker.perform_async
      else
        worker.perform_later
      end
    end
  end
end