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] - Several potential changes #762

Open
pcfreak30 opened this issue Jul 23, 2024 · 4 comments
Open

[FEATURE] - Several potential changes #762

pcfreak30 opened this issue Jul 23, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@pcfreak30
Copy link
Contributor

I believe this would need to be several PR's, but I want feedback on if they should be refactored upstream, the best approach?

v2...LumeWeb:gocron:expose_started_locker

Summary of changes:

  • In executor.go:
    • Added a new channel jobOutUpdateLockRequest to the executor struct.
    • Modified the job execution process to send lock updates through this new channel.
    • Added code to signal the startedChan when a job begins execution.
  • In job.go:
    • Added a new field lastLock to the job struct to store the most recent lock.
    • Added a startedChan channel to the job struct.
    • Implemented new methods for the Job interface:
      • Started(): Returns the startedChan.
      • Lock(): Returns the lastLock.
      • Context(): Returns the job's context.
  • In scheduler.go:
    • Defined a new struct jobOutUpdateLockRequest for lock update requests.
    • Added a new channel jobOutUpdateLockRequest to handle these requests.
    • Implemented a new method jobOutUpdateLockRequest to process lock updates.
    • Modified the main event loop to handle lock update requests.
    • Updated the job initialization process to create the startedChan.

In summary

  • Add to Job interface method to get the active context. I use this to abort a monitor thread if the job is canceled
  • Add ability to get the active Lock if it exists which requires new channel comms between scheduler and executer. I use this to managing the lock directly outside cron library.
  • Add a new startedChan and Started that flags when a task has begun but before the task function is called. I use this for a monitor to wait until the task is actually started.

@JohnRoesler

@pcfreak30 pcfreak30 added the enhancement New feature or request label Jul 23, 2024
@JohnRoesler
Copy link
Contributor

@pcfreak30 I can see the value in these features beyond your use. Happy to review a PR. The diff you have looks pretty straightforward, just some comments and such needed 👍

@pcfreak30
Copy link
Contributor Author

One thing came to mind, would the startedChan be better off as some sort of callback for a "before start" as a job option?

as it stands I think it would need to be a go routine anyways to not block. but my case always uses it ATM.

Thoughts?

@JohnRoesler
Copy link
Contributor

Good point, could do away with startedChan as you can just use the existing https://pkg.go.dev/github.com/go-co-op/gocron/v2#BeforeJobRuns event listener

pcfreak30 added a commit to LumeWeb/gocron that referenced this issue Oct 21, 2024
- Add `jobOutUpdateLockRequest` channel in the executor
- Implement lock update requests in the job execution process
- Add `Lock()` method to the `Job` interface
- Update the scheduler to handle lock update requests
- Add a test case to verify the new locking mechanism
pcfreak30 added a commit to LumeWeb/gocron that referenced this issue Oct 21, 2024


- Add Context() method to Job interface and implement it in job struct
- Update requestJob function to include a timeout flag
- Modify existing methods to use the new requestJob signature
@pcfreak30
Copy link
Contributor Author

@JohnRoesler i have created 2 prs that should sum up everything

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