Skip to content

Lua binding for qless - queue / pipeline management system

License

Notifications You must be signed in to change notification settings

moteus/lua-lluv-qless

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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()

About

Lua binding for qless - queue / pipeline management system

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published