How to use ttl method in elementium

Best Python code snippet using elementium_python

__init__.py

Source:__init__.py Github

copy

Full Screen

1import re2from vFense.core._constants import CPUThrottleValues, DefaultStringLength3from vFense.core.customer._constants import CustomerDefaults4class CustomerCollections():5 Customers = 'customers'6 CustomersPerUser = 'customers_per_user'7class CustomerKeys():8 CustomerName = 'customer_name'9 Properties = 'properties'10 NetThrottle = 'net_throttle'11 CpuThrottle = 'cpu_throttle'12 PackageUrl = 'package_download_url_base'13 ServerQueueTTL = 'server_queue_ttl' # in minutes14 AgentQueueTTL = 'agent_queue_ttl' # in minutes15 Users = 'users' #Mapped Keys16 Groups = 'groups' #Mapped Keys17class CustomerPerUserKeys():18 CustomerName = 'customer_name'19 UserName = 'user_name'20 Id = 'id'21class CustomerPerUserIndexes():22 CustomerName = 'customer_name'23 UserName = 'user_name'24class Customer(object):25 """Used to represent an instance of a customer."""26 def __init__(27 self, name, net_throttle=None, cpu_throttle=None,28 server_queue_ttl=None, agent_queue_ttl=None,29 package_download_url=None30 ):31 """32 Args:33 name (str): The name of the customer34 net_throttle (int): The default net throttling for downloading35 packages for agents in this customer, in KB/s.36 cpu_throttle (str): The default cpu throttling for operations37 in this customer. Has to be a valid cpu throttling keyword.38 valid: ['idle', 'below_normal', 'normal', 'above_normal', 'high']39 server_queue_ttl (int): The default time an operation will sit40 on the server queue, in minutes. Must be above 0.41 agent_queue_ttl (int): The default time an operation will sit42 on the agent queue, in minutes. Must be above 0.43 package_download_url (str): The base url used to construct the44 urls where the packages will be downloaded from.45 Ex:46 'https://192.168.1.1/packages/'47 """48 self.name = name49 self.net_throttle = net_throttle50 self.cpu_throttle = cpu_throttle51 self.server_queue_ttl = server_queue_ttl52 self.agent_queue_ttl = agent_queue_ttl53 self.package_download_url = package_download_url54 if net_throttle:55 self.net_throttle = int(net_throttle)56 if server_queue_ttl:57 self.server_queue_ttl = int(server_queue_ttl)58 if agent_queue_ttl:59 self.agent_queue_ttl = int(agent_queue_ttl)60 def fill_in_defaults(self):61 """Replace all the fields that have None as their value with62 the hardcoded default values.63 64 Use case(s):65 Useful when creating a new customer instance and only want to fill66 in a few fields, then allow the create customer functions call this67 method to fill in the rest.68 """69 if not self.net_throttle:70 self.net_throttle = CustomerDefaults.NET_THROTTLE71 if not self.cpu_throttle:72 self.cpu_throttle = CustomerDefaults.CPU_THROTTLE73 if not self.server_queue_ttl:74 self.server_queue_ttl = CustomerDefaults.SERVER_QUEUE_TTL75 if not self.agent_queue_ttl:76 self.agent_queue_ttl = CustomerDefaults.AGENT_QUEUE_TTL77 def get_invalid_fields(self):78 """Check the customer for any invalid fields.79 Returns:80 (list): List of key/value pair dictionaries corresponding81 to the invalid fields.82 Ex:83 [84 {'customer_name': 'the invalid name in question'},85 {'net_throttle': -10}86 ]87 """88 invalid_fields = []89 if isinstance(self.name, basestring):90 valid_symbols = re.search(91 '((?:[A-Za-z0-9_-](?!\s+")|\s(?!\s*")){1,36})', self.name92 )93 valid_length = len(self.name) <= DefaultStringLength.CUSTOMER_NAME94 if not valid_symbols or not valid_length:95 invalid_fields.append(96 {CustomerKeys.CustomerName: self.name}97 )98 else:99 invalid_fields.append(100 {CustomerKeys.CustomerName: self.name}101 )102 if self.net_throttle:103 if isinstance(self.net_throttle, int):104 if self.net_throttle < 0:105 invalid_fields.append(106 {CustomerKeys.NetThrottle: self.net_throttle}107 )108 else:109 invalid_fields.append(110 {CustomerKeys.NetThrottle: self.net_throttle}111 )112 if self.cpu_throttle:113 if self.cpu_throttle not in CPUThrottleValues.VALID_VALUES:114 invalid_fields.append(115 {CustomerKeys.CpuThrottle: self.cpu_throttle}116 )117 if self.server_queue_ttl:118 if isinstance(self.server_queue_ttl, int):119 if self.server_queue_ttl <= 0:120 invalid_fields.append(121 {CustomerKeys.ServerQueueTTL: self.server_queue_ttl}122 )123 else:124 invalid_fields.append(125 {CustomerKeys.ServerQueueTTL: self.server_queue_ttl}126 )127 if self.agent_queue_ttl:128 if isinstance(self.agent_queue_ttl, int):129 if self.agent_queue_ttl <= 0:130 invalid_fields.append(131 {CustomerKeys.AgentQueueTTL: self.agent_queue_ttl}132 )133 else:134 invalid_fields.append(135 {CustomerKeys.AgentQueueTTL: self.agent_queue_ttl}136 )137 # TODO: check for invalid package url138 return invalid_fields139 def to_dict(self):140 """ Turn the customer fields into a dictionary.141 Returns:142 (dict): A dictionary with the fields corresponding to the143 customer.144 Ex:145 {146 "agent_queue_ttl": 100 ,147 "cpu_throttle": "high" ,148 "customer_name": "default" ,149 "net_throttle": 100 ,150 "package_download_url_base": https://192.168.8.14/packages/,151 "server_queue_ttl": 100152 }153 154 """155 return {156 CustomerKeys.CustomerName: self.name,157 CustomerKeys.NetThrottle: self.net_throttle,158 CustomerKeys.CpuThrottle: self.cpu_throttle,159 CustomerKeys.ServerQueueTTL: self.server_queue_ttl,160 CustomerKeys.AgentQueueTTL: self.agent_queue_ttl,161 CustomerKeys.PackageUrl: self.package_download_url162 }163 def to_dict_non_null(self):164 """ Use to get non None fields of customer. Useful when165 filling out just a few fields to update the customer in the db.166 Returns:167 (dict): a dictionary with the non None fields of this customer.168 """169 customer_dict = self.to_dict()170 return {k:customer_dict[k] for k in customer_dict...

Full Screen

Full Screen

constants.py

Source:constants.py Github

copy

Full Screen

1import random2# TTL (time to live) 秒3class CacheTTLBase(object):4 """5 生成有效期的父类6 """7 # 有效期的基础值8 TTL = 2 * 60 * 609 # 有效期随机的最大上限偏差10 MAX_DELTA = 10 * 6011 @classmethod12 def get_val(cls):13 return cls.TTL + random.randint(0, cls.MAX_DELTA)14class UserProfileCacheTTL(CacheTTLBase):15 # 用户资料缓存有效期16 pass17class UserNotExistsCacheTTL(CacheTTLBase):18 # 记录用户不存在的缓存有效期19 TTL = 10 * 6020 MAX_DELTA = 6021class UserStatusCacheTTL(CacheTTLBase):22 """23 用户状态缓存时间,秒24 """25 TTL = 60 * 6026class UserFollowingsCacheTTL(CacheTTLBase):27 """28 用户关注列表缓存时间,秒29 """30 TTL = 30 * 6031class UserRelationshipCacheTTL(CacheTTLBase):32 """33 用户关系缓存时间,秒34 """35 TTL = 30 * 6036class UserRelationshipNotExistsCacheTTL(CacheTTLBase):37 """38 用户关系不存在数据缓存时间,秒39 """40 TTL = 5 * 6041 MAX_DELTA = 6042class UserAdditionalProfileCacheTTL(CacheTTLBase):43 """44 用户详细资料缓存时间,秒45 """46 TTL = 10 * 6047 MAX_DELTA = 2 * 6048class UserFansCacheTTL(CacheTTLBase):49 """50 用户粉丝列表缓存时间,秒51 """52 TTL = 30 * 6053class UserChannelsCacheTTL(CacheTTLBase):54 """55 用户频道缓存时间,秒56 """57 TTL = 60 * 6058class UserArticleAttitudeCacheTTL(CacheTTLBase):59 """60 用户文章态度缓存时间,秒61 """62 TTL = 30 * 6063class UserArticleAttitudeNotExistsCacheTTL(CacheTTLBase):64 """65 用户文章态度不存在数据缓存时间,秒66 """67 TTL = 5 * 6068 MAX_DELTA = 6069class UserCommentLikingCacheTTL(CacheTTLBase):70 """71 用户文章评论点赞缓存时间,秒72 """73 TTL = 10 * 6074 MAX_DELTA = 2 * 6075class UserCommentLikingNotExistsCacheTTL(CacheTTLBase):76 """77 用户文章评论点赞不存在数据缓存时间,秒78 """79 TTL = 3 * 6080 MAX_DELTA = 6081class ArticleInfoCacheTTL(CacheTTLBase):82 """83 文章信息缓存时间,秒84 """85 TTL = 30 * 6086class ArticleNotExistsCacheTTL(CacheTTLBase):87 """88 文章不存在结果缓存89 为解决缓存击穿,有效期不宜过长90 """91 TTL = 5 * 6092 MAX_DELTA = 6093class ArticleDetailCacheTTL(CacheTTLBase):94 """95 文章详细内容缓存时间,秒96 """97 TTL = 60 * 6098class ArticleUserNoAttitudeCacheTTL(CacheTTLBase):99 """100 用户对文章无态度缓存101 为解决缓存击穿,有效期不宜过长102 """103 TTL = 3 * 60104 MAX_DELTA = 30105class UserArticlesCacheTTL(CacheTTLBase):106 """107 用户文章作品缓存时间,秒108 """109 TTL = 10 * 60110 MAX_DELTA = 2 * 60111class UserArticleCollectionsCacheTTL(CacheTTLBase):112 """113 用户文章收藏缓存时间,秒114 """115 TTL = 10 * 60116 MAX_DELTA = 2 * 60117class ArticleCommentsCacheTTL(CacheTTLBase):118 """119 文章评论列表缓存时间,秒120 """121 TTL = 30 * 60122class CommentRepliesCacheTTL(CacheTTLBase):123 """124 评论回复列表缓存时间,秒125 """126 TTL = 30 * 60127class CommentCacheTTL(CacheTTLBase):128 """129 评论信息缓存时间,秒130 """131 TTL = 30 * 60132class CommentNotExistsCacheTTL(CacheTTLBase):133 """134 评论不存在结果缓存135 为解决缓存击穿,有效期不宜过长136 """137 TTL = 5 * 60138 MAX_DELTA = 60139class AnnouncementDetailCacheTTL(CacheTTLBase):140 """141 系统公告详细信息缓存时间,秒142 """143 TTL = 2 * 60 * 60144class AnnouncementNotExistsCacheTTL(CacheTTLBase):145 """146 公告不存在结果缓存147 为解决缓存击穿,有效期不宜过长148 """149 TTL = 5 * 60150 MAX_DELTA = 60151# 缓存评论最大SCORE152COMMENTS_CACHE_MAX_SCORE = 2e19153# 默认用户头像154DEFAULT_USER_PROFILE_PHOTO = 'Fkj6tQi3xJwVXi1u2swCElotfdCi' # 程序猿155# 阅读历史每人保存数目156READING_HISTORY_COUNT_PER_USER = 100157# 用户搜索历史每人保存数目158SEARCHING_HISTORY_COUNT_PER_USER = 4159# 允许更新关注缓存的TTL限制,秒160ALLOW_UPDATE_FOLLOW_CACHE_TTL_LIMIT = 5161# 默认用户频道缓存有效期,秒162DEFAULT_USER_CHANNELS_CACHE_TTL = 24 * 60 * 60163# 全部频道缓存有效期,秒164ALL_CHANNELS_CACHE_TTL = 24 * 60 * 60165# 允许更新文章评论列表缓存的TTL限制,秒166ALLOW_UPDATE_ARTICLE_COMMENTS_CACHE_TTL_LIMIT = 5167# 系统公告缓存时间,秒...

Full Screen

Full Screen

Train.py

Source:Train.py Github

copy

Full Screen

1# File: Train.py2# Description: A turtle graphics attempt of drawing a choo-choo train3# Student Name: Stephen Rauner 4# Student UT EID: STR4285# Course Name: CS 313E6# Unique Number: 509457# Date Created: 2/28/168# Date Last Modified: 2/29/169import turtle10import math11def drawLine (ttl, x1, y1, x2, y2):12 ttl.penup()13 ttl.goto(x1, y1)14 ttl.pendown()15 ttl.goto(x2, y2)16 ttl.penup()17def tracks(ttl, start_x, num):18 ttl.penup()19 ttl.goto(start_x, -310)20 y = -31021 w = 2322 h = 523 for i in range(num):24 ttl.goto(start_x + (i*45), y)25 ttl.pendown()26 drawLine(ttl, start_x + (i * 45), y, start_x + (i * 45), y - h)27 drawLine(ttl, start_x + (i * 45), y - h, start_x + w + (i * 45), y - h)28 drawLine(ttl, start_x + w + (i * 45), y - h, start_x + w +(i * 45), y)29 ttl.penup()30def spokes(ttl, cen_x, cen_y, r):31 for i in range(8):32 ttl.penup()33 ttl.goto(cen_x, cen_y)34 ttl.tilt(45)35 ttl.pendown()36 ttl.forward(r - 10)37def wheels(ttl):38 # big wheel39 ttl.color("red")40 ttl.penup()41 ttl.goto(-200, -300)42 ttl.pendown()43 ttl.circle(50)44 ttl.penup()45 ttl.goto(-200, -290)46 ttl.pendown()47 ttl.circle(40)48 spokes(ttl, -200, -250, 50)49 ttl.penup()50 ttl.goto(-200, -260)51 ttl.pendown()52 ttl.circle(10) 53 # small wheel 154 ttl.penup()55 ttl.goto(-30, -300)56 ttl.pendown()57 ttl.circle(40)58 ttl.penup()59 ttl.goto(-30, -290)60 ttl.pendown()61 ttl.circle(30)62 spokes(ttl, -30, -260, 40)63 ttl.penup()64 ttl.goto(-30, -265)65 ttl.pendown()66 ttl.circle(5) 67 # small wheel 268 ttl.penup()69 ttl.goto(100, -300)70 ttl.pendown()71 ttl.circle(40)72 ttl.penup()73 ttl.goto(100, -290)74 ttl.pendown()75 ttl.circle(30)76 spokes(ttl, 100, -260, 40)77 ttl.penup()78 ttl.goto(100, -265)79 ttl.pendown()80 ttl.circle(5)81def main():82 turtle.title("Choo-Choo")83 turtle.setup(800, 800, 0, 0)84 turtle.speed(0)85 turtle.ht()86 ttl = turtle.Turtle()87 ttl.ht()88 drawLine(ttl, -300, -300, 300, -300)89 drawLine(ttl, -300, -310, 300, -310)90 count = 1091 tracks(ttl, -290, 13)92 wheels(ttl)93 turtle.done()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run elementium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful