Skip to content

Commit

Permalink
Rename Job & Count UUID to Partition ID
Browse files Browse the repository at this point in the history
Renames the uuid and job_uuid fields to partition ID. This is the more
correct name as this value is not a true UUID, is in-fact a partition
ID, and doesn't need to be globally unique.

```shell
$ grep -nir . -e "uuid"
./go.sum:98:github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
./go.sum:167:github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
$
```

Signed-off-by: joshvanl <me@joshvanl.dev>
  • Loading branch information
JoshVanL committed Jun 25, 2024
1 parent 5021035 commit f3ba860
Show file tree
Hide file tree
Showing 15 changed files with 200 additions and 189 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Leadership keys are associated with an ETCD lease of 20s TTL to prevent stale le
## Counter

An associated `counters` key is used to track the current state of a job that is scheduled.
It includes the last trigger time (if triggered), the number of times the job has been triggered, and the UUID of the associated job with the same name.
It includes the last trigger time (if triggered), the number of times the job has been triggered, and the Partition ID of the associated job with the same name.
Counters are lazily deleted in bulk by a garbage collector that runs every 180s in an effort to reduce pressure of jobs triggering.

The scheduler will never miss triggering jobs.
Expand Down
19 changes: 11 additions & 8 deletions api/counter.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 45 additions & 42 deletions api/job.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func Test_schedule(t *testing.T) {
Begin: &api.JobStored_DueTime{
DueTime: timestamppb.New(now),
},
Uuid: 123,
PartitionId: 123,
Job: &api.Job{
DueTime: ptr.Of(now.Format(time.RFC3339)),
},
Expand Down Expand Up @@ -518,15 +518,15 @@ func Test_schedule(t *testing.T) {
Begin: &api.JobStored_DueTime{
DueTime: timestamppb.New(now),
},
Uuid: 123,
PartitionId: 123,
Job: &api.Job{
DueTime: ptr.Of(now.Format(time.RFC3339)),
},
}
counter := &api.Counter{
LastTrigger: nil,
Count: 0,
JobUuid: 123,
LastTrigger: nil,
Count: 0,
JobPartitionId: 123,
}

jobBytes, err := proto.Marshal(job)
Expand Down Expand Up @@ -599,15 +599,15 @@ func Test_schedule(t *testing.T) {
Begin: &api.JobStored_DueTime{
DueTime: timestamppb.New(now),
},
Uuid: 123,
PartitionId: 123,
Job: &api.Job{
DueTime: ptr.Of(now.Format(time.RFC3339)),
},
}
counter := &api.Counter{
LastTrigger: timestamppb.New(now),
Count: 1,
JobUuid: 123,
LastTrigger: timestamppb.New(now),
Count: 1,
JobPartitionId: 123,
}

jobBytes, err := proto.Marshal(job)
Expand Down
10 changes: 5 additions & 5 deletions internal/counter/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func New(ctx context.Context, opts Options) (*Counter, bool, error) {
client: opts.Client,
schedule: opts.Schedule,
job: opts.Job,
count: &api.Counter{JobUuid: opts.Job.GetUuid()},
count: &api.Counter{JobPartitionId: opts.Job.GetPartitionId()},
yard: opts.Yard,
collector: opts.Collector,
triggerRequest: &api.TriggerRequest{
Expand All @@ -105,10 +105,10 @@ func New(ctx context.Context, opts Options) (*Counter, bool, error) {
return nil, false, err
}

// If the job UUID is the same, recover the counter state, else we start
// again.
if count.GetJobUuid() != opts.Job.GetUuid() {
count = &api.Counter{JobUuid: opts.Job.GetUuid()}
// If the job partition ID is the same, recover the counter state, else we
// start again.
if count.GetJobPartitionId() != opts.Job.GetPartitionId() {
count = &api.Counter{JobPartitionId: opts.Job.GetPartitionId()}
b, err := proto.Marshal(count)
if err != nil {
return nil, false, err
Expand Down
Loading

0 comments on commit f3ba860

Please sign in to comment.