mirror of https://github.com/go-co-op/gocron.git
Fix memory consumption issue by changing jobOutRequest channels to use pointers
Co-authored-by: JohnRoesler <19351306+JohnRoesler@users.noreply.github.com>
This commit is contained in:
parent
7a5ae9640f
commit
1393d798da
|
|
@ -29,7 +29,7 @@ type executor struct {
|
|||
// sends out jobs once completed
|
||||
jobsOutCompleted chan uuid.UUID
|
||||
// used to request jobs from the scheduler
|
||||
jobOutRequest chan jobOutRequest
|
||||
jobOutRequest chan *jobOutRequest
|
||||
|
||||
// sends out job needs to update the next runs
|
||||
jobUpdateNextRuns chan uuid.UUID
|
||||
|
|
|
|||
2
job.go
2
job.go
|
|
@ -1136,7 +1136,7 @@ type job struct {
|
|||
id uuid.UUID
|
||||
name string
|
||||
tags []string
|
||||
jobOutRequest chan jobOutRequest
|
||||
jobOutRequest chan *jobOutRequest
|
||||
runJobRequest chan runJobRequest
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ type scheduler struct {
|
|||
// used to send all the jobs out when a request is made by the client
|
||||
allJobsOutRequest chan allJobsOutRequest
|
||||
// used to send a jobs out when a request is made by the client
|
||||
jobOutRequestCh chan jobOutRequest
|
||||
jobOutRequestCh chan *jobOutRequest
|
||||
// used to run a job on-demand when requested by the client
|
||||
runJobRequestCh chan runJobRequest
|
||||
// new jobs are received here
|
||||
|
|
@ -140,7 +140,7 @@ func NewScheduler(options ...SchedulerOption) (Scheduler, error) {
|
|||
jobsOutForRescheduling: make(chan uuid.UUID),
|
||||
jobUpdateNextRuns: make(chan uuid.UUID),
|
||||
jobsOutCompleted: make(chan uuid.UUID),
|
||||
jobOutRequest: make(chan jobOutRequest, 1000),
|
||||
jobOutRequest: make(chan *jobOutRequest, 1000),
|
||||
done: make(chan error, 1),
|
||||
}
|
||||
|
||||
|
|
@ -159,7 +159,7 @@ func NewScheduler(options ...SchedulerOption) (Scheduler, error) {
|
|||
startedCh: make(chan struct{}),
|
||||
stopCh: make(chan struct{}),
|
||||
stopErrCh: make(chan error, 1),
|
||||
jobOutRequestCh: make(chan jobOutRequest),
|
||||
jobOutRequestCh: make(chan *jobOutRequest),
|
||||
runJobRequestCh: make(chan runJobRequest),
|
||||
allJobsOutRequest: make(chan allJobsOutRequest),
|
||||
}
|
||||
|
|
@ -461,7 +461,7 @@ func (s *scheduler) selectExecJobsOutCompleted(id uuid.UUID) {
|
|||
s.jobs[id] = j
|
||||
}
|
||||
|
||||
func (s *scheduler) selectJobOutRequest(out jobOutRequest) {
|
||||
func (s *scheduler) selectJobOutRequest(out *jobOutRequest) {
|
||||
if j, ok := s.jobs[out.id]; ok {
|
||||
select {
|
||||
case out.outChan <- j:
|
||||
|
|
|
|||
6
util.go
6
util.go
|
|
@ -35,16 +35,16 @@ func callJobFuncWithParams(jobFunc any, params ...any) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func requestJob(id uuid.UUID, ch chan jobOutRequest) *internalJob {
|
||||
func requestJob(id uuid.UUID, ch chan *jobOutRequest) *internalJob {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
return requestJobCtx(ctx, id, ch)
|
||||
}
|
||||
|
||||
func requestJobCtx(ctx context.Context, id uuid.UUID, ch chan jobOutRequest) *internalJob {
|
||||
func requestJobCtx(ctx context.Context, id uuid.UUID, ch chan *jobOutRequest) *internalJob {
|
||||
resp := make(chan internalJob, 1)
|
||||
select {
|
||||
case ch <- jobOutRequest{
|
||||
case ch <- &jobOutRequest{
|
||||
id: id,
|
||||
outChan: resp,
|
||||
}:
|
||||
|
|
|
|||
Loading…
Reference in New Issue