Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.

FindById and job identifiers/human names #31

Open
utrack opened this issue Aug 27, 2015 · 6 comments
Open

FindById and job identifiers/human names #31

utrack opened this issue Aug 27, 2015 · 6 comments

Comments

@utrack
Copy link
Contributor

utrack commented Aug 27, 2015

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
Copy link
Owner

albrow commented Aug 27, 2015

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

@utrack
Copy link
Contributor Author

utrack commented Aug 28, 2015

@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
Copy link
Owner

albrow commented Aug 28, 2015

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
Copy link
Contributor Author

utrack commented Aug 31, 2015

Yup, that's even better :)

@umayr
Copy link

umayr commented Apr 10, 2016

Is there any update on this one? @albrow

@albrow
Copy link
Owner

albrow commented Apr 11, 2016

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants