Core business logic for job management.
Pure functions for creating, updating, and managing background jobs. No side effects - all I/O happens in the shell layer.
Core business logic for job management. Pure functions for creating, updating, and managing background jobs. No side effects - all I/O happens in the shell layer.
(aggregate-stats jobs)Calculate aggregate statistics for jobs.
Args: jobs - Collection of jobs
Returns: Stats map with counts and averages
Calculate aggregate statistics for jobs. Args: jobs - Collection of jobs Returns: Stats map with counts and averages
(calculate-duration job)Calculate job execution duration.
Args: job - Job map
Returns: Duration in milliseconds or nil if not completed
Calculate job execution duration. Args: job - Job map Returns: Duration in milliseconds or nil if not completed
(calculate-retry-delay retry-count config jitter-ms)Calculate delay before next retry using exponential backoff.
Args: retry-count - Current retry attempt (0-indexed) config - Retry configuration map with: :backoff-strategy - :linear, :exponential, or :constant :initial-delay-ms - Initial delay (default 1000ms) :max-delay-ms - Maximum delay (default 60000ms) :jitter - Whether jitter is enabled (default true) jitter-ms - Jitter in milliseconds (provided by caller)
Returns: Delay in milliseconds
Calculate delay before next retry using exponential backoff.
Args:
retry-count - Current retry attempt (0-indexed)
config - Retry configuration map with:
:backoff-strategy - :linear, :exponential, or :constant
:initial-delay-ms - Initial delay (default 1000ms)
:max-delay-ms - Maximum delay (default 60000ms)
:jitter - Whether jitter is enabled (default true)
jitter-ms - Jitter in milliseconds (provided by caller)
Returns:
Delay in milliseconds(can-retry? job)Check if job can be retried.
Args: job - Job map
Returns: true if job has retries remaining
Check if job can be retried. Args: job - Job map Returns: true if job has retries remaining
(cancel-job job now)Mark job as cancelled.
Args: job - Job map now - Current timestamp (provided by caller)
Returns: Updated job with :cancelled status
Mark job as cancelled. Args: job - Job map now - Current timestamp (provided by caller) Returns: Updated job with :cancelled status
(complete-job job result now)Mark job as completed successfully.
Args: job - Job map result - Result data from job execution now - Current timestamp (provided by caller)
Returns: Updated job with :completed status
Mark job as completed successfully. Args: job - Job map result - Result data from job execution now - Current timestamp (provided by caller) Returns: Updated job with :completed status
(create-job job-input job-id now)Create a new job from input.
Args: job-input - Map with :job-type, :args, and optional fields job-id - UUID for the job (provided by caller) now - Current timestamp (provided by caller)
Returns: Complete job map with defaults
Create a new job from input. Args: job-input - Map with :job-type, :args, and optional fields job-id - UUID for the job (provided by caller) now - Current timestamp (provided by caller) Returns: Complete job map with defaults
(fail-job job error now)Mark job as failed.
Args: job - Job map error - Error map with :message, :type, :stacktrace now - Current timestamp (provided by caller)
Returns: Updated job with :failed or :retrying status
Mark job as failed. Args: job - Job map error - Error map with :message, :type, :stacktrace now - Current timestamp (provided by caller) Returns: Updated job with :failed or :retrying status
(filter-executable-jobs jobs now)Filter jobs that are ready for execution.
Args: jobs - Collection of jobs now - Current time (Instant)
Returns: Filtered collection of executable jobs
Filter jobs that are ready for execution. Args: jobs - Collection of jobs now - Current time (Instant) Returns: Filtered collection of executable jobs
(job-summary job)Create summary of job for monitoring.
Args: job - Job map
Returns: Summary map with key fields
Create summary of job for monitoring. Args: job - Job map Returns: Summary map with key fields
(jobs-by-status jobs)Group jobs by status.
Args: jobs - Collection of jobs
Returns: Map of status -> jobs
Group jobs by status. Args: jobs - Collection of jobs Returns: Map of status -> jobs
(prepare-retry job retry-config now jitter-ms)Prepare a failed job for retry.
Args: job - Failed job map retry-config - Retry configuration now - Current timestamp (provided by caller) jitter-ms - Jitter in milliseconds (provided by caller)
Returns: Job ready for retry with new execute-at
Prepare a failed job for retry. Args: job - Failed job map retry-config - Retry configuration now - Current timestamp (provided by caller) jitter-ms - Jitter in milliseconds (provided by caller) Returns: Job ready for retry with new execute-at
(ready-for-execution? job now)Check if job is ready to be executed.
Args: job - Job map now - Current time (Instant)
Returns: true if job should be executed now
Check if job is ready to be executed. Args: job - Job map now - Current time (Instant) Returns: true if job should be executed now
(schedule-job job-input job-id execute-at now)Create a scheduled job for future execution.
Args: job-input - Job input map job-id - UUID for the job execute-at - Instant when job should run now - Current timestamp (provided by caller)
Returns: Job map with execute-at set
Create a scheduled job for future execution. Args: job-input - Job input map job-id - UUID for the job execute-at - Instant when job should run now - Current timestamp (provided by caller) Returns: Job map with execute-at set
(schedule-retry job retry-config now jitter-ms)Calculate when job should be retried.
Args: job - Failed job map retry-config - Retry configuration now - Current timestamp (provided by caller) jitter-ms - Jitter in milliseconds (provided by caller)
Returns: Instant when job should be retried
Calculate when job should be retried. Args: job - Failed job map retry-config - Retry configuration now - Current timestamp (provided by caller) jitter-ms - Jitter in milliseconds (provided by caller) Returns: Instant when job should be retried
(sort-by-priority jobs)Sort jobs by priority (critical > high > normal > low).
Args: jobs - Collection of jobs
Returns: Sorted collection
Sort jobs by priority (critical > high > normal > low). Args: jobs - Collection of jobs Returns: Sorted collection
(start-job job now)Mark job as running.
Args: job - Job map now - Current timestamp (provided by caller)
Returns: Updated job with :running status
Mark job as running. Args: job - Job map now - Current timestamp (provided by caller) Returns: Updated job with :running status
(valid-job-transition? from-status to-status)Check if status transition is valid.
Args: from-status - Current status to-status - Desired status
Returns: true if transition is allowed
Check if status transition is valid. Args: from-status - Current status to-status - Desired status Returns: true if transition is allowed
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |