Skip to content

Commit

Permalink
Be more careful around scheduler state handling (#858)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperl authored Sep 29, 2023
1 parent 49ae509 commit 0a1156e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
5 changes: 4 additions & 1 deletion src/service/containers.toit
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ class ContainerManager:
return null

create -> ContainerJob?
--name/string --id/uuid.Uuid --description/Map --state/any
--name/string
--id/uuid.Uuid
--description/Map
--state/any
--reader/Reader?=null:
if reader:
writer/containers.ContainerImageWriter := ?
Expand Down
2 changes: 1 addition & 1 deletion src/service/device.toit
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class Device:
Stores the scheduler jobs state information in memory that
is preserved across deep sleeping.
*/
scheduler-job-states-update value/Map -> none:
scheduler-job-states-update value/Map? -> none:
ram-store_ RAM-SCHEDULER-JOB-STATES_ value

/**
Expand Down
4 changes: 2 additions & 2 deletions src/service/jobs.toit
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ abstract class Job:
// same with has_run_after_boot.
scheduler-delayed-until_/JobTime? := null

constructor .name scheduler-state/any:
set-scheduler-state_ scheduler-state
constructor .name state/any:
set-scheduler-state_ state

abstract is-running -> bool
is-background -> bool: return false
Expand Down
11 changes: 1 addition & 10 deletions src/service/scheduler.toit
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,7 @@ class Scheduler:
else:
return schedule-wakeup_ now
finally:
critical-do:
transition --runlevel=Job.RUNLEVEL-STOP
// For now, we only update the storage bucket when we're
// shutting down. This means that if hit an exceptional
// case, we will reschedule all jobs.
job-states := {:}
jobs_.do: | job/Job |
if state := job.scheduler-state:
job-states[job.name] = state
device_.scheduler-job-states-update job-states
critical-do: transition --runlevel=Job.RUNLEVEL-STOP

add-jobs jobs/List -> none:
jobs.do: add-job it
Expand Down
20 changes: 12 additions & 8 deletions src/service/service.toit
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ run-artemis device/Device server-config/ServerConfig -> Duration
containers ::= ContainerManager logger scheduler
broker := BrokerService logger server-config

// Steal the job states, so if we do not shut down
// cleanly, we start in a fresh state.
job-states := device.scheduler-job-states
device.scheduler-job-states-update null

// Set up the basic jobs.
synchronize-state := job-states.get SynchronizeJob.NAME
synchronizer/SynchronizeJob := SynchronizeJob logger device containers broker synchronize-state
Expand Down Expand Up @@ -70,14 +74,14 @@ run-artemis device/Device server-config/ServerConfig -> Duration
// so we have to be careful and clean up anyway.
critical-do: provider.uninstall

// For now, we only update the storage bucket when we're
// shutting down. This means that if hit an exceptional
// case, we will reschedule all jobs.
job-states = {:}
scheduler.jobs_.do: | job/Job |
if state := job.scheduler-state:
job-states[job.name] = state
device.scheduler-job-states-update job-states
// For now, we only update the storage bucket when we're
// shutting down cleanly. This means that if hit an exceptional
// case, we will reschedule all jobs.
job-states = {:}
scheduler.jobs_.do: | job/Job |
if state := job.scheduler-state:
job-states[job.name] = state
device.scheduler-job-states-update job-states

containers.setup-deep-sleep-triggers

Expand Down

0 comments on commit 0a1156e

Please sign in to comment.