#1948: AbstractJob.kt

projectforge-common/src/main/kotlin/org/projectforge/jobs/AbstractJob.kt Job Framework, projectforge-business/src/main/kotlin/org/projectforge/framework/jobs/AbstractJob.kt 43 lines · 14 code · 25 comments · 4 blank
Abstract base class for background jobs in ProjectForge. Supports queuing strategies (none, per-queue, per-queue-and-user, refuse), optional timeout (default 120s), progress tracking (total/processed count), and cancellation via Kotlin coroutines. Jobs have a lifecycle and expose readAccess / writeAccess for permission checks. Integrates with UserGroupCache for owner display.

Architecture

Class Hierarchy

Key Enums

EnumValuesPurpose
QueueStrategyNONE, PER_QUEUE, PER_QUEUE_AND_USER, REFUSE_PER_QUEUE, REFUSE_PER_QUEUE_AND_USERControls whether job blocks/refuses new jobs in the same area
StatusRUNNING, WAITING, FINISHED, FAILED, CANCELLED, REFUSEDImplements I18nEnum; drives ordering in job list
ErrorCodeTIMEOUT_WHILE_WAITING, REFUSED_BY_ANOTHER_RUNNING_JOBReason for failure/refusal

Job Lifecycle

The lifecycle is managed by JobHandler:

  1. addJob() — job added to handler, status = WAITING
  2. Queue check — compares against running jobs via isBlocking()
  3. onBeforeStart() — hook before execution
  4. start() — sets status to RUNNING, calls run()
  5. On success: onFinish()onAfterFinish()onAfterTermination()
  6. On cancellation: cancel()onBeforeCancel()onAfterCancel()onAfterTermination()
  7. On failure: markJobAsFailed()onAfterException()onAfterTermination()

Key Properties

PropertyTypeDescription
titleStringHuman-readable title for display/logging
areaString?Groups jobs; queue strategy scoped to same area
ownerIdLong?User who started the job
idIntAuto-incrementing unique job ID
timeoutIntTimeout in ms (from constructor param in seconds)
timeoutReachedBooleanTrue if job exceeded timeout while RUNNING
isActiveBooleanConvenience: status==RUNNING && coroutineJob.isActive
progressPercentageIntComputed from processedNumber/totalNumber
terminatedForDeletionBooleanTrue if terminated > 1 hour ago (cleanup)
infoStringMarkdown-formatted status info (owner, times, status, title)

Permissions

Integration Points

Git History

868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
cba940301 Migration stuff in progress...
67805f2fc ThreadLocalUserContext.user -> ThreadLocalUserContext.loggedInUser (renamed)
4c04cfd65 MAJOR-CHANGE! Migration of integer id's to Long id's (including fk's etc.)
b6092df09 Copyright 2023 -> 2024
ab45d51fa Copyright 2001-2022 -> 2001-2023.
163492453 WIP: Jobs and Bank account records.
232a91c5a BaseUserGroupRightUtils implemented. WIP BankingPlugin and jobs-handling.
38bec971a ThreadLocal -> Kotlin
09b3f0df7 WIP: Jobmonitor. ListStatisticsSupport -> MarkdownBuilder
fcc4c67f6 WIP: Jobmonitor.
a1646e91a WIP: Banking plugin (and new import module).
d93f61491 WIP: Banking plugin (and new import module).
cd69cc40f WIP: Banking plugin (and new import module).
f68cda98e Jobmonitor.
67eed70e4 WIP: Banking plugin (and new import module). JobHandler/monitor started.