Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] - Exposing job definition/scheduling information #746

Open
chicknsoup opened this issue Jun 28, 2024 · 5 comments
Open

[FEATURE] - Exposing job definition/scheduling information #746

chicknsoup opened this issue Jun 28, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@chicknsoup
Copy link

Is your feature request related to a problem? Please describe

I want to list out all scheduled jobs with detailed definition (job type, scheduling intervals, last run, next runs, etc..) like in version v1

Describe the solution you'd like

It would be nice to expose internalJob information via Job structure.

@chicknsoup chicknsoup added the enhancement New feature or request label Jun 28, 2024
@JohnRoesler
Copy link
Contributor

Hi @chicknsoup that information could be added to the public Job structure and populated from the internal job when passed to the caller.

@chicknsoup
Copy link
Author

Hi @chicknsoup that information could be added to the public Job structure and populated from the internal job when passed to the caller.

Can I have an example, please? Thank you.

@JohnRoesler
Copy link
Contributor

  1. add the fields to the job struct ->

    gocron/job.go

    Lines 947 to 959 in 212db8e

    var _ Job = (*job)(nil)
    // job is the internal struct that implements
    // the public interface. This is used to avoid
    // leaking information the caller never needs
    // to have or tinker with.
    type job struct {
    id uuid.UUID
    name string
    tags []string
    jobOutRequest chan jobOutRequest
    runJobRequest chan runJobRequest
    }
  2. add methods to the Job interface to return that information ->

    gocron/job.go

    Lines 926 to 945 in 212db8e

    type Job interface {
    // ID returns the job's unique identifier.
    ID() uuid.UUID
    // LastRun returns the time of the job's last run
    LastRun() (time.Time, error)
    // Name returns the name defined on the job.
    Name() string
    // NextRun returns the time of the job's next scheduled run.
    NextRun() (time.Time, error)
    // NextRuns returns the requested number of calculated next run values.
    NextRuns(int) ([]time.Time, error)
    // RunNow runs the job once, now. This does not alter
    // the existing run schedule, and will respect all job
    // and scheduler limits. This means that running a job now may
    // cause the job's regular interval to be rescheduled due to
    // the instance being run by RunNow blocking your run limit.
    RunNow() error
    // Tags returns the job's string tags.
    Tags() []string
    }
  3. pass the information from the internalJob to the job struct ->

    gocron/scheduler.go

    Lines 500 to 508 in 9d27ea8

    func (s *scheduler) jobFromInternalJob(in internalJob) job {
    return job{
    in.id,
    in.name,
    slices.Clone(in.tags),
    s.jobOutRequestCh,
    s.runJobRequestCh,
    }
    }

@chicknsoup
Copy link
Author

Thanks, but there are different types of jobs (cronJob, durationJob, dailyJob, weeklyJob, etc.) and I'm wondering about how to expose their definition via a single method as they have different fields.

@JohnRoesler
Copy link
Contributor

@chicknsoup that's a good point. I'm giving it some thought. Initial reaction, we have some enum type that denotes the job type. And then perhaps an interface that stores the different job schedules...hm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants