I have a requirement to run a chron job weekly on only a single instance of a java spring service running on multiple aws instances in a cluster. I have the freedom to spawn an instance of same service in a different cluster for handling the special load of the chron job. I am thinking of implementing a sqs listener module in the service which will get triggered once the specially configured lambda on new cluster publishes a sqs message. Since this lambda will only publish in the queue of new instance it should be possible to ensure that only one chron is working at most at a time (for processing data once) with dedicated cluster resources. If we want to keep app level code and config the same across all of the instances, is this approach good to achieve the chron job run schedule as specified ?
Running chron job on a single instance of spring service deployed on aws
161 views Asked by Aditya Raman At
2
There are 2 answers
0
Aditya Raman
On
It can also be achieved using Redis. Since, it works in single thread so even if multiple nodes request to read redis simultaneously only one thread will be able to do so and later can update so that other threads get ineligible to run cron logic. This can be achieved if we are using command like INCR to update and return value in one call. Eg. set :-(K, {0,timestamp}) (done by all nodes) incr K returned 1 to only 1 node rest will get 2,3...
Related Questions in SPRING
- HTTPS configuration in Spring Boot, server returning timeout
- Multi Tenancy in Spring - Partitioned Data Approach
- How to create beans of the same class for multiple template parameters in Spring
- org.telegram.telegrambots.meta.exceptions.TelegramApiException: Bot token and username can't be empty
- Springboot: How to get an entity optional property and check null?
- How do I propagate the current SecurityContext to my @RabbitListener in Spring Boot?
- Spring's XML based bean configuration for Object Mapper's Case Insensitive property
- Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. I'm using Postgresql
- springboot class org.hibernate.mapping.Bag cannot be cast to class org.hibernate.mapping.SimpleValue
- Issue while deploying JDK 17 and Spring 6 application in Tomcat 10.1.20
- Spring JPA Data Auditing - How to design it?
- Springframework test: Async not started
- Error: Cannot invoke "jakarta.servlet.http.HttpSession.getAttribute(String)" because "session" is null
- How does spring-retry determine which methods to retry when @Retryable is placed at the class level?
- problem with edge server registration in Eureka
Related Questions in AWS-LAMBDA
- Query parameter works fine with fastapi application when tested locally but not working when the FastAPI application is deployed on AWS lambda
- Lambda endpoint for the Google OAuth callback does not recieve the access_token
- Golang lambda upload image into s3 static website
- Unable to run Bash Script using AWS Custom Lambda Runtime
- Call an External API from AWS Lambda
- AWS Lambda Trigger For Same S3 File Name In Quick Succession
- Trouble Extracting Request Body in Flask-Lambda Application Deployed on AWS Lambda via AWS SAM
- S3 pre-signed url not working on whatsapp cloud Api
- 'Load failed' error when trying to create a function in AWS lambda
- Using Python CDK to bundle dotnet 8 code to AWS Lambda function
- AWS WebSocket API return forbidden (403) error when sending message
- Pass integer value in json serializable Python Object
- AWS Lambda successfully called with 'Function URL', but not with 'API Gateway'
- How do I create a *clean* AWS lambda function in python?
- Laravel Vapor Queue Dynamic DB Connection Issue for Different Requests
Related Questions in DISTRIBUTED-SYSTEM
- How to avoid duplicates with the pull-based subscribe model?
- Micrometer & Prometheus with Java subprocesses that can't expose HTTP
- SQL connection throws error when adding DistributedSession, SessionMiddleware
- How to use NFS locks or any other mechanism to keep data in sync on multiple mountpoints
- The two data nodes return different results
- How to run an MPI program across multiple docker containers without manually ssh'ing
- How do I parallelize writing a list of Pyspark dataframes across all worker nodes?
- Does AWS use distributed systems?
- How to version control a source code which communicates with database?
- Searching for succ(p+1) in Chord systems
- How to design a long running process that can continue after an outtage?
- akka.cluster.ddata.Replicator$Internal$DeltaPropagation message from clusterReceptionist replicator is dropped because it exceeds the size limit
- In the storage-computing separation deployment mode, why does one of the three nodes have no disk space?
- Out-of-order AppendEntries in Raft
- Automatic Load Balancer with Locust 2.20.0 on Windows - High Ping and Scaling Challenges
Related Questions in CHRON
- Converting a timestamp involving hours and minutes to datetime
- calculating yearly average based on monthly data
- read.zoo is not returning needed date format
- Converting format %H %M %S (no leading 0s) to HH:MM:SS in r
- How to format the times and get a time delta in R using chron
- Fix inconsistent values in a field in R requiring time values
- Convert column of time (as character decimals from Excel) to time in R
- Prevent the same job to run twice node-cron
- How to change date format to 2019-Feb-07 to 2019-02-07 in R?
- Running chron job on a single instance of spring service deployed on aws
- Formatting numeric values to time in R
- datetime object to minutes: I need 3 packages
- Convert chr to time format using chorn
- How to programmatically ad a character to a string in R
- xset in BASH script does not work under Cron
Related Questions in SQSLISTENER
- How to prevent SqsListener from spamming error logs
- Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) with @SqlListener using
- SQS JMS Implementation Listener hang issue
- Could not find class [io.awspring.cloud.jdbc.config.annotation.AmazonRdsInstanceConfiguration] while using spring-cloud-starter-aws
- Due to a large backlog in an SQS FIFO queue we introduced a new message group. Not seeing any messages from the new groups being sent
- Spring boot SQS listener makes message visible if error/exception in processing
- How to use AWS SQSExtendedClient library to make it work asynchrously using JMSListener java
- How do I mock simpleMessageListenerContainer during the test cases
- I have a service using Nestjs and when i set up an SQS consumer, using '@ssut/nestjs-sqs', it fails
- What is SpringBoot @SqsListener equivalent in quarkus if it is available and if not how to built the one?
- Failed to Creation of subsegment with @SQSListener for AWS Xray
- SqsListener can't map object after Migration to 3.0
- Any other way of using sqs queues for different environments other than multiple application.properties in spring boot?
- interceptor concept for SqsListener
- spring-cloud-aws sqslistener stops listen after a period and release notes
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
I’m a little bit “rusty” with was (used to work with a couple of years ago last time) but in general what you describe seems to be a good solution with the following caveats:
You should make sure that amazon SQS provides “exactly once” semantics because otherwise you might end up triggering the message twice in some cases. I know that do, but probably you should turn it on somehow and the price will slightly change, you should check
Make sure you handle the exceptions that might arise during the job execution in a proper manner, so that the job won’t be re-executed on another instance if the exception cause the sqs driver to interact with sqs server in a way that the message will get back to the sqs queue
What happens if the instance stops during the job execution - that might happen of course, what is the desired behavior? Rerun the job on another instance? Or maybe let it go and rely on the fact that the next time the job will run it will “cover up” for the previous period as well, this depends on the actual application logic
Your application will depend on “external scheduler” (implemented via lambda of course) so that you won’t have any cron triggering logic in the application itself. This is something just to be aware of, not something you can do with. This might be a good thing or not, depending on your environment. For example, if you want to test the job scheduling in CI or something you should have Lambda Deployed and being able to actually send the message to trigger the job execution. Also you should have an SQS available.
So again, I see that you can make it work in general, of course depending on your application architecture other solutions might also apply, as you may use Kubernetes Jobs, Redis, any form of distributed cache to co-ordinate on which node the job actually runs, many things.