Git Product home page Git Product logo

qyu's Introduction

Qyu 九

Gem Version Build Status Maintainability codecov Press

Requirements:

  • Ruby 2.4.0 or newer

Installation

Add this line to your application's Gemfile:

gem 'qyu'

And then execute:

$ bundle

Or install it yourself as:

$ gem install qyu

Configuration

To start using Qyu; you need a queue configuration and a state store configuration. Here's an example:

Qyu.configure(
  queue: {
    type: :memory
  },
  store: {
    type: :memory,
    lease_period: 60
  },
  # optional Defaults to STDOUT
  logger: Logger.new(STDOUT)
)

Usage

[1] Connect all instances to the same state store and message queue
[2] Create a workflow
[3] Initialize a worker as follows

w = Qyu::Worker.new do
  # callbacks
  callback :execute, :before do
    Qyu.logger.info 'Waiting for task..'
  end

  callback :execute, :after do
    Qyu.logger.info 'Done'
  end

  # payload validation
  validates :times, presence: true, type: :integer

  # failure queue
  failure_queue false

  # timeout in seconds for each task processed by the worker
  timeout 120
end

w.work('queue-name') do |task|
  # to get the payload passed to the task
  task.payload
  # = { 'param_1' => true, 'param_2': [10, 11, 12], 'param_3' => 2 }

  # get the job
  task.job

  # to manually start a task
  task.job.create_task(task, 'next-task-name', payload)
rescue StandardError => ex
  # If you rescue the error for debugging or reporting purposes, you have to raise it at the end
  #
  # do something
  #
  raise ex
end

[4] Start worker
[5] Start creating Jobs using the previously created workflow

Plugins

The memory queue and store is just for testing purposes. For production; use one of the following:

Stores

ActiveRecord: https://github.com/QyuTeam/qyu-store-activerecord
Redis: https://github.com/QyuTeam/qyu-store-redis

Queues

Amazon SQS: https://github.com/QyuTeam/qyu-queue-sqs
Redis: https://github.com/QyuTeam/qyu-queue-redis

Glossary

Workflow

The workflow specifies the entry points (starts), the tasks, their order, eventual dependencies between them, and synchronisation conditions.

Job

A job is essentially a collection of tasks and an initial JSON payload.

Task

A task is one unit of work. It is an instance of an entry from a workflow. You can think of it as the workflow's entries define the classes, while a task is a materialised instance of it, saved in the state store and enqueued on the message queue.

In the state store a task has:

  • id
  • name - it appears as the key in the workflow's tasks
  • queue_name - the queue where the task was enqueued on creation
  • payload - the entry/input parameters for the particular task
  • parent_task_id - the ID of the task which created/enqueued the current task

When a task is created (saved & enqueued) then its id is put in a JSON message { task_id: task.id} and enqueued on the specified task's message queue. When a worker picks up the message from the queue, decodes the task id, and retrieves it from the state store.

Worker

A worker is sitting on a queue, waiting for something.

Sync Worker

A worker waiting for other workers to finish

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/QyuTeam/qyu.

qyu's People

Contributors

oss92 avatar bejmuller avatar zzet avatar

Stargazers

Honeybadgers55 avatar Mark avatar Igor Zubkov avatar John Mettraux avatar  avatar  avatar  avatar Fabio Mucciante avatar slava pocheptsov avatar Andrei Horak avatar Sherllo Chen avatar  avatar Luis Belloch avatar George Kussumoto avatar Conail Stewart avatar Leonardo Falk avatar Vinh Quốc Nguyễn avatar Sam Moore avatar Gabriel Mazetto avatar Lucas Santos da Costa avatar Andrii Konchyn avatar Maxim Filippovich avatar Maurizio Del Corno avatar Jean-Denis Koeck avatar m.b. avatar Yunzheng avatar Roland Koch avatar Morton Fox avatar George Opritescu avatar Kotov Aleksandr avatar Alex Maslov avatar Batuhan KATIRCI avatar Łukasz avatar  avatar Andrei Subbota avatar Nikolay Kolev avatar  avatar Alexander Kirillov avatar omar mowafi avatar

Watchers

Victor Godoy Poluceno avatar  avatar James Cloos avatar Pedro Calgaro avatar  avatar Lee Clissett avatar

Forkers

zzet

qyu's Issues

Need documentation

I have several questions about Qyu and I suspect your documentation could be improved so that others don't raise the same questions.

Workers all must be able to connect to the single shared state store. They do this to retrieve job information needed for processing and to determine what state to move a job to when a task is complete. Is that right? Could this be a bottleneck? How do I change the workflow? What happens to jobs that are already in process when I change a workflow? How do I ensure all workers get the changes? Do they need to be restarted, or will they automatically pick them up?

What is the relationship of tasks to queues? Should each task have it's own queue or is it acceptable to use a single queue for all tasks? Can a worker service multiple queues? Is it up to the worker to determine what task type it is being asked to execute? What is the best way to do that?

How should exceptions be handled? Does Qyu provide any facility for retrying jobs? Is there any logging facilities in Qyu?

Do long running jobs ever timeout? Is the timeout configurable? What happens to jobs that timeout?

Failure in schedule_renewal task operation

INFO -- : [177e9831-fc1a-4a42-ae07-855b8fe4c567] Worker started for queue 'queue_name'
INFO -- : [177e9831-fc1a-4a42-ae07-855b8fe4c567] Worker processed 1 tasks from queue `queue_name`
#<Thread:0x0000563af8768598@/bundle/gems/qyu-1.0.1/lib/qyu/models/task.rb:205 run> terminated with exception (report_on_exception is true):
/bundle/gems/qyu-1.0.1/lib/qyu/utils.rb:6:in `seconds_after_time': undefined method `+' for nil:NilClass (NoMethodError)
 	from /bundle/gems/qyu-1.0.1/lib/qyu/models/task.rb:203:in `schedule_renewal'
 	from /bundle/gems/qyu-1.0.1/lib/qyu/models/task.rb:214:in `block in schedule_renewal'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.