connorads / lockbot

🔒 Coordinate use of your team's shared resources, in Slack 🤝
https://lockbot.app
MIT License
57 stars 7 forks source link

Make locks expire after or at a user specified time #7

Open connorads opened 4 years ago

connorads commented 4 years ago

Could use DynamoDB TTL but it has limited time guarantees and wouldn't notify users.

connorads commented 4 years ago

https://medium.com/@zaccharles/there-is-more-than-one-way-to-schedule-a-task-398b4cdc2a75

connorads commented 3 years ago

Would be nice if ...

1 minute CRON job? 1440 minutes a day ... scan, query for expiry time? Store the reply URL so that it can reply to channel on deletion. Do these links expire?

frshwtr commented 3 years ago

If a TTL can trigger a lambda, it's possible that a webhook event could be emitted to notify that a lock has expired. It is possible to trigger lambdas on DynamoDB changes, hopefully the TTL feature can be picked up by that. Though reading the article, it looks like more thought may need to be put into this approach.

Scan is a pretty expensive DynamoDB call. Depending on the size of your database, it can be a pretty read-intensive call.

connorads commented 3 years ago

The DynamoDB TTL could trigger a lambda according to this and this . The trouble is that it might not actually get deleted for up to 48 hours which is not very useful for Lockbot where a 1 minute error margin would probably be tolerable 😢

The scan could indeed get expensive! I'm not a DynamoDB expert but we might be able to make use of a secondary index on the expiry time so we could do queries on it. But indexes aren't free either. I believe they can reduce read costs but increase storage costs. Which might be a reasonable trade off in the case of a polling CRON job.

Hopefully there's a simple solution lurking somewhere 🧐

floydspace commented 3 years ago
  • Locks could be set to expire at a particular minute
  1. We could use EventBridge.PutRule to acquire cron scheduled event per Resource, so as soon as we add a resource we PutRule with defined cron, and it will run a lambda on a certain time and delete the Resource from dynamo. we do not need any new indexes, we do not have to scan because the rule can be configured with input, so we exactly know the key.

  2. I suggest using the following interface: /lock dev 1h so it could be h, m or d, or even pattern like 1h30m indicating how much time it will last. or it could be exact time 9:00 - means 9 am

  3. I would love to work on it with my pace

connorads commented 3 years ago

Hey @floydspace sounds like a great idea!

  1. I'm just reading about this EventBridge.PutRule - sounds very promising! Going to read some more.
  2. The format sounds good. I think one thing to work around with exact times would be timezones. I think this could be helped by using this convenient example provided by the Slack Bolt JS documentation on context.
  3. As you please sir 👍

I've tried to keep the README.md and CONTRIBUTING.md up to date but it may not be entirely clear how to setup a local dev environment or deploy to a dev environment. If you find anything confusing please do ask me and feel free to update the docs.

If you'd like a walkthrough of the project or discuss anything then I'm be happy to jump on a call.

Join the Lockbot Slack Workspace if you'd like to chat.

connorads commented 3 years ago

Note to self: https://medium.com/@najibahalim/aws-custom-event-bridge-with-serverless-framework-ac76a5ebdf79

https://github.com/rubenkaiser/serverless-offline-eventBridge

alpeshvas commented 2 years ago
  • Locks could be set to expire at a particular minute
  1. We could use EventBridge.PutRule to acquire cron scheduled event per Resource, so as soon as we add a resource we PutRule with defined cron, and it will run a lambda on a certain time and delete the Resource from dynamo. we do not need any new indexes, we do not have to scan because the rule can be configured with input, so we exactly know the key.

  2. I suggest using the following interface: /lock dev 1h so it could be h, m or d, or even pattern like 1h30m indicating how much time it will last. or it could be exact time 9:00 - means 9 am

  3. I would love to work on it with my pace

Great solution, but I think there is a limit of 100 rules per account which means with a single aws account, lockbot can have at max 100 resources

karimzmi commented 5 months ago

This would be a good feature to have. Is there a plan to add it? We use the app and it is great but we do want a way to release locks automatically after certain default time.