From 88653b36b0a3863c066cde3f6e0dd859fe630c06 Mon Sep 17 00:00:00 2001 From: Artyom Dubinin Date: Fri, 2 Jul 2021 16:59:41 +0300 Subject: [PATCH] readme: examples of new functionality Added an example of how to use the new features for the user. Description of how to run luatests. Run luatest via Makefile with tap tests Closes: #50 --- README.md | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 26a258d..1c29c13 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,10 @@ tuple and performs the expiry itself: either deletes it (memcache), or does something smarter, like put a smaller representation of the data being deleted into some other space. -### Example -``` lua +### Examples + +Simple version: +```lua box.cfg{} space = box.space.old job_name = "clean_all" @@ -27,6 +29,44 @@ expirationd.start(job_name, space.id, is_expired, { }) ``` +Сustomized version: +```lua +expirationd.start(job_name, space.id, is_expired, { + -- name or id of the index in the specified space to iterate over + index = "exp", + -- one transaction per batch + -- default is false + atomic_iteration = true, + -- delete data that was added a year ago + -- default is nil + start_key = function( task ) + return clock.time() - (365*24*60*60) + end, + -- delete it from the oldest to the newest + -- default is ALL + iterator_type = "GE", + -- stop full_scan if delete a lot + -- returns true by default + process_while = function( task ) + if task.args.max_expired_tuples >= task.expired_tuples_count then + task.expired_tuples_count = 0 + return false + end + return true + end, + -- this function must return an iterator over the tuples + iterate_with = function( task ) + return task.expire_index:pairs({ task.start_key() }, { iterator = task.iterator }) + :take_while( function( tuple ) + return task:process_while() + end ) + end, + args = { + max_expired_tuples = 1000 + } +}) +``` + ## Expirationd API ### `expirationd.start (name, space_id, is_tuple_expired, options)` @@ -112,4 +152,4 @@ Get statistics of task ## Testing -Simply start `tarantool test.lua` +Simply start `make test`