albrow / jobs

A persistent and flexible background jobs library for go.
MIT License
499 stars 47 forks source link

FindById and job identifiers/human names #31

Open utrack opened 9 years ago

utrack commented 9 years ago

So jobs.FindById attempts to retrieve job by its unique ID, which is generated randomly - so it's not really possible to fetch a job by "some-identifier". Is there any way to list jobs by their readable name?

albrow commented 9 years ago

@utrack I'm not sure I understand. Can you elaborate on what you mean by "readable name"?

utrack commented 9 years ago

@albrow well uh, term "job type identifiers" is a better term : )

Here's what i mean:

welcomeEmailJobs, err := jobs.RegisterType("welcomeEmail", 3, func(user *User) error {
   // here be dragons
})

// spam poor guy
job, err := welcomeEmailJobs.ScheduleRecurring(100, time.Now(),time.Second*60, &User{EmailAddress: "foo@example.com"})
if err != nil {
    // Handle err
}

... somewhere else
tasks,err := jobs.FindById("welcomeEmail") // it doesn't work but nice to have
// -- tasks would contain job from previous snippet or at least unique string identifiers, which can be used to retrieve scheduled tasks by current FindById()

The problem I experience is: there's recurring task that gets registered each time app is started; as they can't be cleaned up in every possible case (say, power failure for app's node) the scheduled tasks pile up.

albrow commented 9 years ago

Okay I think I understand now. What you want to do is get all jobs of a particular Type? I don't like the idea of saying that FindById takes a job id or a job type as an argument. It's conflating two different things.

What I would rather do is add a new method on Type. Something like FindAll. Continuing from your example, you could run something like:

tasks,err := welcomEmailJobs.FindAll()
for _, task := range tasks {
    // Do what you want with each task.
}

Does that cover your use case?

utrack commented 9 years ago

Yup, that's even better :)

umayr commented 8 years ago

Is there any update on this one? @albrow

albrow commented 8 years ago

@umayr sorry for going dark on this one.

I have many projects to maintain and moving forward I'm going to focus on bug fixes and maintenance. I will not be adding any new features to Jobs in the near future, but I would be happy to review PRs. I have also been speaking with a few developers to try and find additional maintainers.

I will update the Development Status section of the README to reflect this.