How to use get_scheduled_rule_func method in localstack

Best Python code snippet using localstack_python

events_listener.py

Source: events_listener.py Github

copy

Full Screen

...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...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

How To Use Playwright For Web Scraping with Python

In today’s data-driven world, the ability to access and analyze large amounts of data can give researchers, businesses & organizations a competitive edge. One of the most important & free sources of this data is the Internet, which can be accessed and mined through web scraping.

A Complete Guide To CSS Container Queries

In 2007, Steve Jobs launched the first iPhone, which revolutionized the world. But because of that, many businesses dealt with the problem of changing the layout of websites from desktop to mobile by delivering completely different mobile-compatible websites under the subdomain of ‘m’ (e.g., https://m.facebook.com). And we were all trying to figure out how to work in this new world of contending with mobile and desktop screen sizes.

A Complete Guide To CSS Houdini

As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????

Project Goal Prioritization in Context of Your Organization’s Strategic Objectives

One of the most important skills for leaders to have is the ability to prioritize. To understand how we can organize all of the tasks that must be completed in order to complete a project, we must first understand the business we are in, particularly the project goals. There might be several project drivers that stimulate project execution and motivate a company to allocate the appropriate funding.

Stop Losing Money. Invest in Software Testing

I was once asked at a testing summit, “How do you manage a QA team using scrum?” After some consideration, I realized it would make a good article, so here I am. Understand that the idea behind developing software in a scrum environment is for development teams to self-organize.

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 localstack 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