- Defined in:
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
#id ⇒ String
Id of this worker.
Instance Method Summary collapse
- #initialize(jobs_queue) ⇒ Worker constructor
Methods included from Helpers::Async
#initialize(jobs_queue) ⇒ Worker
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
#id ⇒ String (readonly)
Returns id of this worker.
23 24 25
# File 'lib/karafka/processing/worker.rb', line 23 def id @id end