Best Python code snippet using localstack_python
events_listener.py
Source: events_listener.py
...51 json.dumps(event["event"]),52 )53def _get_events_tmp_dir():54 return os.path.join(config.TMP_FOLDER, EVENTS_TMP_DIR)55def get_scheduled_rule_func(data):56 def func(*args, **kwargs):57 rule_name = data.get("Name")58 client = aws_stack.connect_to_service("events")59 targets = client.list_targets_by_rule(Rule=rule_name)["Targets"]60 if targets:61 LOG.debug(62 "Notifying %s targets in response to triggered Events rule %s"63 % (len(targets), rule_name)64 )65 for target in targets:66 arn = target.get("Arn")67 event_str = target.get("Input") or "{}"68 event = json.loads(event_str)69 attr = aws_stack.get_events_target_attributes(target)70 try:71 send_event_to_target(arn, event, target_attributes=attr)72 except Exception as e:73 LOG.info(74 f"Unable to send event notification {truncate(event)} to target {target}: {e}"75 )76 return func77def convert_schedule_to_cron(schedule):78 """Convert Events schedule like "cron(0 20 * * ? *)" or "rate(5 minutes)" """79 cron_regex = r"\s*cron\s*\(([^\)]*)\)\s*"80 if re.match(cron_regex, schedule):81 cron = re.sub(cron_regex, r"\1", schedule)82 return cron83 rate_regex = r"\s*rate\s*\(([^\)]*)\)\s*"84 if re.match(rate_regex, schedule):85 rate = re.sub(rate_regex, r"\1", schedule)86 value, unit = re.split(r"\s+", rate.strip())87 if "minute" in unit:88 return "*/%s * * * *" % value89 if "hour" in unit:90 return "* */%s * * *" % value91 if "day" in unit:92 return "* * */%s * *" % value93 raise Exception("Unable to parse events schedule expression: %s" % schedule)94 return schedule95def handle_put_rule(data):96 schedule = data.get("ScheduleExpression")97 enabled = data.get("State") != "DISABLED"98 if schedule:99 job_func = get_scheduled_rule_func(data)100 cron = convert_schedule_to_cron(schedule)101 LOG.debug("Adding new scheduled Events rule with cron schedule %s" % cron)102 job_id = JobScheduler.instance().add_job(job_func, cron, enabled)103 rule_scheduled_jobs = EventsBackend.get().rule_scheduled_jobs104 rule_scheduled_jobs[data["Name"]] = job_id105 return True106def handle_delete_rule(rule_name):107 rule_scheduled_jobs = EventsBackend.get().rule_scheduled_jobs108 job_id = rule_scheduled_jobs.get(rule_name)109 if job_id:110 LOG.debug("Removing scheduled Events: {} | job_id: {}".format(rule_name, job_id))111 JobScheduler.instance().cancel_job(job_id=job_id)112def handle_disable_rule(rule_name):113 rule_scheduled_jobs = EventsBackend.get().rule_scheduled_jobs...
Check out the latest blogs from LambdaTest on this topic:
The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.
QA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!