Code Challenge 1

Rules

You can provide a solution to this challenge using any tools, resources, or languages you like.

 

Background

A core function of Shopventory is to make sure we always have up to date information for a customer. In inventory management, being real-time or near real-time for a customer makes a big impact on the customer experience. Our system relies on webhooks from the customer's point of sale to tell us when a transaction has occurred. This is near-real time but there are some cases where this will fail and we need a backup method to make sure we're not missing anything.

 

Problem

On our system, each customer's account is run on an interval to make sure we don't miss any information. For example, each account in our system needs to run once every 15 minutes. You will write a piece of code that will do this scheduling. This function will be called EVERY minute at the top of the minute.

 

Why?

A common question we get asked is why do it every minute? Why not just schedule all accounts every 15 minutes? The answer to that question is because we want to build a scalable solution. If we schedule every 15 minutes, our servers will have very spiky utilization coinciding with when we schedule accounts. This is a way to spread out the load so we have more even utilization.

 

Your solution

You have access to one piece of information, the list of account ids which will be in this format

account_ids = [1000, 1001, 1002, 1003 ...]

Create a function that will schedule these accounts every 15 minutes by returning ONLY the account ids that need to run each minute. You can be guaranteed that this function will be called every minute, on the minute passing you only the account IDs on the system.

For example, account 1000 may run at minute 0, minute 15, minute 30, minute 45 and needs to be in the list of accounts returned each time the function is called during those minutes.

You can use any libraries or imports available with a clean environment using the language of your choice.

 

Function definition

function get_account_ids_to_run (account_ids_list) {

        account_ids_to_return = [];

        // Insert your logic here.

        // account_ids_list is defined above. Expect it to be an array of integers (account ids). 

        return account_ids_to_return;    

}

 

Bonus points if your scheduler function can schedule accounts every X hours or every X days.

Submit your solution AND any questions about this challenge to bach@shopventory.com