注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
第一轮coding
设计一个简单的file system,称为workspace,假设root node已经存在。有两种resource,folder和table,支持四种操作
- 可以插入一个新的resource
- 遍历一个resource及immediate children
- 删除一个resource及所有的children
- 移动一个resource
import uuid
class Resource:
def init(self, resource_name, resource_type, parent_id = None):
self.id = str(uuid.uuid4())
self.resource_name = resource_name
self.resource_type = resource_type
self.parent_id = parent_id
self.children = []
class ClayWorkspace:
def init(self):
self.resources = {}
root = Resource("root", "folder")
self.resources[root.id] = root
self.root_id = root.id
def create_resource(self, resource_name, resource_type, parent_folder_id):
resource = Resource(resource_name, resource_type, parent_folder_id)
self.resources[resource.id] = resource
parent = selfall draw from the same poolWorkspace is tied to a billing plan, and gets more credits each time the billing plan cyclesDisplay the credit balance to the user (live update 5-10 seconds)Charge credits when users run actionsBlock any actions for which the workspace doesn't have enough credits, and show an error in the table cell主要就是(1)准备跑一个action的时候先看看是不是credit够,注意race condition以及其他consistency (2)如何显示credit
问了不少关于scale和failure mode的问题
|