https://github.com/fastlane/taskqueue
ruby implementation of a simple dispatch queue
https://github.com/fastlane/taskqueue
Last synced: 5 months ago
JSON representation
ruby implementation of a simple dispatch queue
- Host: GitHub
- URL: https://github.com/fastlane/taskqueue
- Owner: fastlane
- License: mit
- Created: 2018-02-02T03:23:36.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-29T14:49:31.000Z (about 6 years ago)
- Last Synced: 2024-05-02T01:08:32.369Z (over 1 year ago)
- Language: Ruby
- Size: 25.4 KB
- Stars: 13
- Watchers: 13
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://twitter.com/taquitos)
[](https://github.com/fastlane/TaskQueue/blob/master/LICENSE)# TaskQueue
A ruby implementation of a simple dispatch queue using procsCurrently, `TaskQueue` only has api for dispatching tasks asynchronously.
## Example
```ruby
# Create a queue with as many workers as you want or 1 for a serial queue
queue = TaskQueue.new(name: 'my concurrent queue', number_of_workers: 5)
task = Task.new(work_block: proc {
# some work to be done
})
queue.add_task_async(task: task)
``````ruby
# Or don't supply the number of workers and you'll only get 1, making it a serial queue
queue = TaskQueue.new(name: 'my serial queue')
task = Task.new(work_block: proc {
# some work to be done
})
queue.add_task_async(task: task)
```## Recreatable Tasks
The tasks that are created from the mixin `RecreatableTask` can be recovered in future executions of the `TaskQueue` where their were enqueued originally.
### Example
```ruby
# We define a task that includes RecreatableTask
class HelloToRecreatableTask
include TaskQueue::RecreatableTask# The run! method receives a collection of params and defines the real execution of the task itself.
def run!(**params)
puts "Hello #{params}"
end# In case the queue gets deallocated with RecreatableTasks on its queue, the hash returned by this function will be stored. Make sure that all values are JSON encodable.
def params_to_hash
{ to: "fastlane" }
end
endqueue = TaskQueue(name: 'test queue')
task = HelloToRecreatableTask.new.to_task
queue.add_task_async(task: task)```
## Run tests
```
bundle exec rspec
```