PIPELINE_START = 2 PIPELINE_END = 4 DELETE_COMPLETE = 8 DELETE_FAILED = 16 DELETE_FILTERED = 32 PIPELINE_ERROR = 64 DELETE_CANCEL = 128 STATS_REPORT = 256
local function has_flag(value, flag)
return (value & flag) ~= 0
end
local function object_details(event)
local parts = {}
if event.key then
table.insert(parts, "key=" .. event.key)
end
if event.version_id then
table.insert(parts, "version_id=" .. event.version_id)
end
if event.size then
table.insert(parts, "size=" .. tostring(event.size))
end
if event.last_modified then
table.insert(parts, "last_modified=" .. event.last_modified)
end
if event.e_tag then
table.insert(parts, "e_tag=" .. event.e_tag)
end
if event.error_message then
table.insert(parts, "error=" .. event.error_message)
end
if event.message then
table.insert(parts, "message=" .. event.message)
end
return table.concat(parts, ", ")
end
function on_event(event)
local et = event.event_type
if has_flag(et, PIPELINE_START) then
print(string.format("[s3rm] Pipeline started (dry_run=%s, event_type=%d)",
tostring(event.dry_run), et))
local details = object_details(event)
if #details > 0 then
print(" " .. details)
end
end
local dry = event.dry_run and "[dry-run] " or ""
if has_flag(et, DELETE_COMPLETE) then
print(string.format("[s3rm] %sDeleted: %s", dry, object_details(event)))
end
if has_flag(et, DELETE_FAILED) then
print(string.format("[s3rm] %sFAILED: %s", dry, object_details(event)))
end
if has_flag(et, DELETE_FILTERED) then
print(string.format("[s3rm] %sFiltered: %s", dry, object_details(event)))
end
if has_flag(et, PIPELINE_ERROR) then
print(string.format("[s3rm] %sERROR: %s", dry, object_details(event)))
end
if has_flag(et, DELETE_CANCEL) then
print(string.format("[s3rm] %sCancelled: %s", dry, object_details(event)))
end
if has_flag(et, STATS_REPORT) then
print(string.format(
"[s3rm] %sStats: deleted_objects=%d, deleted_bytes=%d, failed=%d, skipped=%d, "
.. "errors=%d, duration=%.1fs, throughput=%.1f obj/s",
dry,
event.stats_deleted_objects or 0,
event.stats_deleted_bytes or 0,
event.stats_failed_objects or 0,
event.stats_skipped_objects or 0,
event.stats_error_count or 0,
event.stats_duration_sec or 0,
event.stats_objects_per_sec or 0))
end
if has_flag(et, PIPELINE_END) then
print(string.format("[s3rm] Pipeline finished (dry_run=%s)",
tostring(event.dry_run)))
local details = object_details(event)
if #details > 0 then
print(" " .. details)
end
end
end