Module: AsyncBlock

Defined in:
lib/async_block.rb,
lib/async_block/version.rb,
lib/async_block/constants.rb,
lib/async_block/async_wrapper_job.rb,
lib/async_block/custom_active_job.rb,
lib/async_block/block_source_service.rb

Overview

AsyncBlock - A usable code block for rails to run your code asynchronously, this will help in preventing writing of new jobs to run smaller pieces of code

Defined Under Namespace

Classes: AsyncWrapperJob, BlockToSource, CustomActiveJob, SourceToBlock

Constant Summary collapse

VERSION =
'0.3.3'
DEFAULT_QUEUE_NAME =
'async_block_run'

Class Method Summary collapse

Class Method Details

.run(queue: nil, delay: nil, &block) ⇒ Object



11
12
13
14
15
16
# File 'lib/async_block.rb', line 11

def self.run(queue: nil, delay: nil, &block)
  source = BlockToSource.new(block).convert
  queue ||= DEFAULT_QUEUE_NAME
  delay = nil if delay.present? && !delay.instance_of?(ActiveSupport::Duration)
  AsyncWrapperJob.set(wait: delay, queue: queue.to_sym).perform_later(source)
end