Giter Club home page Giter Club logo

lua-lluv-qless's Introduction

lua-lluv-qless

Licence Build Status Coverage Status

Lua Bindings for qless

Usage

Test job

-- this is separate Lua module which export `perform` function
-- This function accept 2 args
-- 1 - QLessJob object
-- 2 - `done` callback. Function have to call this function 
--      when job complete or fail.
local uv = require "lluv"

local function perform(job, done)

  -- get work data
  local i = job.data.counter
  local t = job.data.interval

  -- start async job
  local timer = uv.timer():start(0, t, function(self)
    print(job, '#', i) i = i - 1

    if i == 0 then
      self:close()
      -- can just pass `done` as callback
      return job:complete(done)
    end
  end)

  -- to handle messages form server we can use EventEmitter API
  job:on('lock_lost', function(self, event, data)
    timer:close()
    -- we do not need call `job:complete`/`job:fail` so just call `done`
    -- we have not pass any error because worker class already know
    -- that this job lost its lock so it just ignore any error.
    done()
  end)

end

return {
  perform = perform
}

Worker

local uv                = require 'lluv'
local QLessWorkerSerial = require 'lluv.qless.worker.serial'

local worker = QLessWorkerSerial.new{
  queues    = {'test-queue'};
  reserver  = 'ordered';
  concurent = 2;
}

worker:run()

uv.run()

Client

local uv    = require 'lluv'
local QLess = require 'lluv.qless'

local qless = QLess.new()

local queue = qless:queue('test-queue')

queue:put("myjobs.test", { counter = 10; interval = 1000 }, function(self, err, jid)
  qless:close()
end)

uv.run()

lua-lluv-qless's People

Contributors

moteus avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

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.