Skip to content

Commit

Permalink
publish queue depth on enqueue/dequeue
Browse files Browse the repository at this point in the history
  • Loading branch information
robacarp committed Jan 6, 2024
1 parent 466ddf7 commit 4c6a30a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/mosquito/queue.cr
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ module Mosquito

def enqueue(job_run : JobRun) : JobRun
Log.trace { "Enqueuing #{job_run} for immediate execution" }
metric { publish @publish_context, {title: "enqueue-job", job_run: job_run.id} }
backend.enqueue job_run
metric {
publish @publish_context, {title: "enqueue-job", job_run: job_run.id, depth: size}
}
job_run
end

def enqueue(job_run : JobRun, in interval : Time::Span) : JobRun
Expand All @@ -102,7 +105,9 @@ module Mosquito

def enqueue(job_run : JobRun, at execute_time : Time) : JobRun
Log.trace { "Enqueuing #{job_run} at #{execute_time}" }
metric { publish @publish_context, {title: "defer-job", job_run: job_run.id, until: execute_time} }
metric {
publish @publish_context, {title: "defer-job", job_run: job_run.id, until: execute_time}
}

backend.schedule job_run, execute_time
end
Expand All @@ -111,7 +116,7 @@ module Mosquito
return if empty?

if job_run = backend.dequeue
metric { publish @publish_context, {title: "dequeue", job_run: job_run.id} }
metric { publish @publish_context, {title: "dequeue", job_run: job_run.id, depth: size} }

job_run
else
Expand Down

0 comments on commit 4c6a30a

Please sign in to comment.