mirror of
https://github.com/ANL-CEEESA/UnitCommitment.jl.git
synced 2025-12-07 08:48:51 -06:00
web: backend: Make JobProcessor more abstract
This commit is contained in:
@@ -4,36 +4,30 @@
|
||||
|
||||
using Backend
|
||||
using Test
|
||||
using HiGHS
|
||||
|
||||
function jobs_test_usage()
|
||||
@testset "JobProcessor" begin
|
||||
# Setup job directory
|
||||
job_id = "qwe123"
|
||||
job_dir = joinpath(Backend.basedir, "jobs", job_id)
|
||||
mkpath(job_dir)
|
||||
cp(fixture("case14.json.gz"), joinpath(job_dir, "input.json.gz"))
|
||||
|
||||
try
|
||||
# Create processor with HiGHS optimizer
|
||||
processor = JobProcessor(optimizer = HiGHS.Optimizer)
|
||||
|
||||
# Start the worker
|
||||
start(processor)
|
||||
|
||||
# Push job to queue
|
||||
put!(processor, job_id)
|
||||
|
||||
# Stop worker (wait for jobs to finish)
|
||||
sleep(0.1)
|
||||
stop(processor)
|
||||
|
||||
# Check that solution file exists
|
||||
output_path = joinpath(job_dir, "output.json")
|
||||
@test isfile(output_path)
|
||||
finally
|
||||
# Cleanup
|
||||
rm(job_dir, recursive = true, force = true)
|
||||
# Define dummy work function
|
||||
received_job_id = []
|
||||
function work_fn(job_id)
|
||||
@show received_job_id
|
||||
push!(received_job_id, job_id)
|
||||
end
|
||||
|
||||
# Create processor with work function
|
||||
processor = JobProcessor(; work_fn)
|
||||
|
||||
# Start the worker
|
||||
start(processor)
|
||||
|
||||
# Push job to queue
|
||||
put!(processor, "test")
|
||||
|
||||
# Wait for job to complete
|
||||
sleep(0.1)
|
||||
stop(processor)
|
||||
|
||||
# Check that the work function was called with correct job_id
|
||||
@test received_job_id[1] == "test"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user