Job in Job Example

This example demonstrates how to call a job from inside another job.

Two approaches are possible:

  1. Executing secondary jobs synchronously, as part of the parent job.

  2. Spawning the secondary jobs to be executed later by the worker, as separate jobs.

Code

jobs/run_sync.rb
jobs/run_async.rb
jobs/sub_job.rb
# This job will call the other jobs synchronously and display progress
# in the dashboard
class RunSync < Jobly::Job
def execute(count: 10)
total count
count.times do |i|
at i
puts "Executing Job ##{i}"
SubJob.execute number: i
end
at count, "Done"
end
end

Commands to Try

cd examples/job-in-job
# Start the server and worker
foreman start
# From another terminal, send the jobs to the owrker
jobly send RunSync count:20
jobly send RunAsync count:10