Skip to content

Commit

Permalink
readme: examples of new functionality
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ArtDu authored and ligurio committed Jul 6, 2021
1 parent c9c5d05 commit 88653b3
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand 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)`
Expand Down Expand Up @@ -112,4 +152,4 @@ Get statistics of task

## Testing

Simply start `tarantool test.lua`
Simply start `make test`

0 comments on commit 88653b3

Please sign in to comment.