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

#async_call, included

Constructor Details

#initialize(jobs_queue) ⇒ Worker

Parameters:



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

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

Instance Attribute Details

#idString (readonly)

Returns id of this worker.

Returns:

  • (String)

    id of this worker



23
24
25
# File 'lib/karafka/processing/worker.rb', line 23

def id
  @id
end