Class: Karafka::Processing::Worker

Inherits:
Object
  • Object
show all
Includes:
Helpers::Async
Defined in:
lib/karafka/processing/worker.rb

Overview

Workers are used to run jobs in separate threads. Workers are the main processing units of the Karafka framework.

Each job runs in three stages:

- prepare - here we can run any code that we would need to run blocking before we allow
            the job to run fully async (non blocking). This will always run in a blocking
            way and can be used to make sure all the resources and external dependencies
            are satisfied before going async.

- call - actual processing logic that can run sync or async

- teardown - it should include any code that we want to run after we executed the user
             code. This can be used to unlock certain resources or do other things that are
             not user code but need to run after user code base is executed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Async

#alive?, #async_call, included

Constructor Details

#initialize(jobs_queue) ⇒ Worker

Parameters:



30
31
32
33
34
# File 'lib/karafka/processing/worker.rb', line 30

def initialize(jobs_queue)
  @id = SecureRandom.hex(6)
  @jobs_queue = jobs_queue
  @non_wrapped_flow = worker_job_call_wrapper == false
end

Instance Attribute Details

#idString (readonly)

Returns id of this worker.

Returns:

  • (String)

    id of this worker



26
27
28
# File 'lib/karafka/processing/worker.rb', line 26

def id
  @id
end