Skip to content

feat: make PendingTasksRunner concurrency configurable via Wendy.setup#221

Open
jangoes wants to merge 2 commits intolevibostian:mainfrom
jangoes:semaphore-value-update
Open

feat: make PendingTasksRunner concurrency configurable via Wendy.setup#221
jangoes wants to merge 2 commits intolevibostian:mainfrom
jangoes:semaphore-value-update

Conversation

@jangoes
Copy link
Copy Markdown

@jangoes jangoes commented Jul 15, 2025

Related GitHub Issues

#220

Problem

The concurrency level for running tasks in PendingTasksRunner was previously hardcoded to 1, allowing only serial execution. There was no way to configure or increase the number of concurrent tasks, limiting performance and flexibility for use cases that could benefit from parallelism.

Solution

  • Introduced a new semaphoreValue parameter to Wendy.setup, allowing users to configure the maximum number of concurrent tasks at startup.
  • The semaphoreValue is stored in WendyConfig and used when initializing the singleton PendingTasksRunner.

Testing

  • Added automated tests.
  • Manually tested.

- Add semaphoreValue parameter to Wendy.setup to control max concurrent tasks
- Store semaphoreValue in WendyConfig and use it when initializing PendingTasksRunner
- Update unit tests to verify semaphoreValue configuration
@jangoes jangoes force-pushed the semaphore-value-update branch from aef155f to e7a0a45 Compare July 15, 2025 11:29
@levibostian levibostian changed the base branch from latest to main July 16, 2025 11:51
@levibostian
Copy link
Copy Markdown
Owner

Greatly appreciate you opening up a PR for this feature. I do agree, it would be great to have this implemented. It would be a great feature to have.

Looking through the PR code, I am realizing now that there are more changes required to fully implement this feature. The entire codebase has the assumption that only 1 task runs at a time so in order to implement this feature it will require modifying a lot of different pieces of the code. While glancing over the code, here are some code that will need modified:

  • var currentlyRunningTask: PendingTask? {
    - needs to support multiple tasks being run.
  • the runTask function can be called directly to run a task manually. So if we allow this function to be called in a non-serial way, the function needs to be smart enough to make sure that it doesn't run the same task twice, for example.
  • The public API, Wendy.swift, has comments talking about there only being 1 task that runs at a time but those might only be comments that need updated. The code that enforces this are not located in that file.

Regarding the PR's implementation approach, I wonder if we might consider some simplifications. For example, I wonder if this would work:

  • In the runAllTasks function, when it's called, could we create N number of Task{}s and have all of those Tasks run the while loop that is inside of the runAllTasks function?
    • We would need to keep track of what task each Task is running to make sure that only 1 Task runs a given task at a time.
    • Also, pendingTasksManager.getNextTaskToRun(lastSuccessfulOrFailedTaskId, filter: filter) would need modified to return a task that another Task is not running already. Perhaps we could pass this in via the filter? Or, we add functionality to the manager where when we call getNextTaskToRun, remembers what task it returned and assumes that a runner will be running that task. Then we add another function to the manager to tell it if a task failed so it can be retried later.

It's worth noting that pendingTasksManager currently assumes serial execution of tasks, so adapting it to support parallelism would be another important change.


Lastly, this feature will require a lot of automated tests, including integration tests, to verify it works as intended. If this feature has a bug in it, it could cause some serious damage.

I understand this message might seem like a significant amount of work, and I appreciate your efforts. This is indeed one of the more complex features that could be integrated into this codebase. Hope this message doesn't sound discouraging.

@jangoes
Copy link
Copy Markdown
Author

jangoes commented Jul 17, 2025

Hi @levibostian ,

Thanks for the detailed feedback — that all makes sense. I’ll take some time to think through the changes needed and see how best to approach it when I get the chance.

Appreciate the thoughtful review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants