Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

General use scheduler for jobs like Auto ON/OFF #271

Closed
Assignees
johnstcn
Labels
apiArea: HTTP API
Milestone
@misskniss

Description

@misskniss

Create a scheduler/executor implementation for workspace auto on/off.

  • Add tableworkspace_lifecycle_job

    CREATETYPEworkspace_lifecycle_operationAS ENUM ('stop','start')CREATETABLEworkspace_lifecycle_job (  id uuidNOT NULL,-- unique job ID  created_attimestamp with time zoneNOT NULL,-- when the job was created  updated_attimestamp with time zoneNOT NULL,-- when the job was last updated  started_attimestamp with time zone,-- when the job was started, null means it's pending  cancelled_attimestamp with time zone,-- when the job was cancelled, null means it hasn't been cancelled  completed_attimestamp with time zone,-- when the job was completed, null means it hasn't finished yet  errortext,-- any errors encountered from the job  workspace_id uuidNOT NULL,-- target workspace  operation workspace_lifecycle_operationNOT NULL,-- start or stop  deadlinetimestamp with time zoneNOT NULL,--  when the job is to be executedPRIMARY KEY (id))
  • Add tableworkspace_lifecycle_job_logs

    CREATETABLEworkspace_lifecycle_job_logs (    id uuidNOT NULL,-- unique row id    job_id uuidNOT NULL,-- uuid of the workspace lifecycle job that created it    created_attimestamp with time zoneNOT NULL,-- when the logs were created    level log_levelNOT NULL,-- level of the log    outputcharacter varying(1024)NOT NULL-- content of the log);
  • Add required methods toquerier.go:

    • AcquireWorkspaceLifecycleJob acquires the lock for a single workspace lifecycle job that isn't started, completed, or cancelled using SKIP LOCKED.
    • InsertWorkspaceLifecycleJob inserts a new row into theworkspace_lifecycle_job table
    • InsertWorkspaceLifecycleJobLogs inserts a new row into theworkspace_lifecycle_job_logs table
    • UpdateWorkspaceLifecycleJobByID updates a row of theworkspace_lifecycle_job_logs table
    • UpdateWorkspaceLifecycleJobWithCancelByID marks a row of theworkspace_lifecycle_job table as cancelled
    • UpdateWorkspaceLifecycleJobWithCompleteByID marks a row of theworkspace_lifecycle_job table as completed
  • Create aWorkspaceLifecycleJobScheduler that schedules starting and stopping workspaces at their scheduled start time/stop time

    • A goroutine tied to the application lifecycle will iterate over all workspaces periodically.
    • If a workspace is running and has a defined auto-stop time, if there is no corresponding auto-stop job pending then create said job.
    • If a workspace is stopped and has a defined auto-start time, if there is no corresponding auto-start job pending then create said job.
    • If an auto-start job is pending for a workspace that has no defined auto-start time, mark the job as cancelled.
    • If an auto-stop job is pending for a workspace that has no defined auto-stop time, mark the job as cancelled.
  • Create anWorkspaceLifecycleJobExecutor that executes jobs fromworkspace_lifecycle_job:

    • A goroutine tied to the application lifecycle will continuously wait for a pending workspace lifecycle job that has not been claimed.
    • When an unclaimed job is found:
      • Mark the job as claimed (settingstarted_at andupdated_at)
      • Triggers the workspace stop/start unless the workspace is already in the desired state (stopped for auto-stop, running for auto-start)
      • Mark the job as completed

Metadata

Metadata

Assignees

Labels

apiArea: HTTP API

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp