mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-01 06:41:41 +00:00
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.
32 lines
496 B
Ruby
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
|