Module: Card::ActManager::EventDelay

Included in:
Card::ActManager
Defined in:
lib/card/act_manager/event_delay.rb

Overview

methods for handling delayed events

Instance Method Summary collapse

Instance Method Details

#contextualize_delayed_event(act_id, card, env, auth) ⇒ Object

If active jobs (and hence the integrate_with_delay events) don't run in a background process then Card::Env.deserialize! decouples the controller's params hash and the Card::Env's params hash with the effect that params changes in the CardController get lost (a crucial example are success params that are processed in CardController#soft_redirect)



11
12
13
14
15
16
17
# File 'lib/card/act_manager/event_delay.rb', line 11

def contextualize_delayed_event act_id, card, env, auth
  if delaying?
    contextualize_for_delay(act_id, card, env, auth) { yield }
  else
    yield
  end
end

#contextualize_for_delay(act_id, card, env, auth, &block) ⇒ Object

The whole ActManager setup is gone once we reach a integrate with delay event processed by ActiveJob. This is the improvised resetup to get subcards working.



28
29
30
31
32
33
34
35
36
37
# File 'lib/card/act_manager/event_delay.rb', line 28

def contextualize_for_delay act_id, card, env, auth, &block
  self.act = Act.find act_id if act_id
  with_env_and_auth env, auth do
    return yield unless act

    run_act(act.card || card) do
      act_card.director.run_delayed_event act, &block
    end
  end
end

#delaying?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/card/act_manager/event_delay.rb', line 19

def delaying?
  const_defined?("Delayed") &&
    Delayed::Worker.delay_jobs &&
    Card.config.active_job.queue_adapter == :delayed_job
end

#with_env_and_auth(env, auth) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/card/act_manager/event_delay.rb', line 39

def with_env_and_auth env, auth
  Card::Auth.with auth do
    Card::Env.with env do
      yield
    end
  end
end