Git Product home page Git Product logo

crontab.lua's Introduction

crontab.lua

lua crontab

参考资料:

中文使用说明


--传说中的测试代码

function RunTests()

-- the following calls are equivalent
function printMessage(a )
  print('Hello',a)
end

local cron = crontab.new()

local c1 = cron:after( 5, printMessage)
local c2 = cron:after( 5, print, {'Hello'})

c1:update(2) -- will print nothing, the action is not done yet
c1:update(5) -- will print 'Hello' once

c1:reset() -- reset the counter to 0

-- prints 'hey' 5 times and then prints 'hello'
while not c1:update(1) do
  print('hey')
end

-- Create a periodical clock:
local c3 = cron:every( 10, printMessage)

c3:update(5) -- nothing (total time: 5)
c3:update(4) -- nothing (total time: 9)
c3:update(12) -- prints 'Hello' twice (total time is now 21)

-------------------------------------
c1.deleted = true
c2.deleted = true
c3.deleted = true

------------------------------
--测试一下match
print('----------------------------------')
assert(match('*',14) == true)
assert(match('12-15',14) == true)
assert(match('18-21',14) == false)
assert(match('18,21',14) == false)
assert(match('18,21,14',14) == true)

--加一个定时器1分钟后执行
cron:update(1000)

--加入一个定时器每分钟执行
cron:addCron('每秒执行', '* * * * *', print, {'.......... cron'})

cron:update((60-os.time()%60)*1000)
cron:update(30*1000)
cron:update(31*1000)
cron:update(1)
cron:update(60*1000)		--打印两次

end

crontab.lua's People

Contributors

linbc 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.