Files
openfoodnetwork/spec/services/job_processor_spec.rb
Maikel Linke b19456535d Isolate report rendering in separate child process
Sidekiq doesn't have any features to limit memory usage or execution
time. We need a separate process for this. Forking avoids the boot time
of a fresh process and copy-on-write ensures minimal memory overheads.
2023-01-18 23:12:26 +00:00

32 lines
496 B
Ruby

# frozen_string_literal: true
require 'spec_helper'
class TestJob < ActiveJob::Base
def initialize
@file = Tempfile.new("test-job-result")
super
end
def perform(message)
@file.write(message)
end
def result
@file.rewind
@file.read
end
end
describe JobProcessor do
describe ".perform_forked" do
let(:job) { TestJob.new }
it "executes a job" do
JobProcessor.perform_forked(job, "hello")
expect(job.result).to eq "hello"
end
end
end