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
160 Views Asked by Aditya Raman At
2
There are 2 best solutions below
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
- Redirect inside java interceptor
- Spring RestTemplate passing the type of the response
- spring-integration-dsl-groovy-http return null when i use httpGet method
- Custom Spring annotation for request parameters
- Spring - configure Jboss Intros for xml with java config?
- HTTP Status 404 - Not Found in Spring 3.2.7
- AndroidAnnotations how to use setBearerAuth
- android I/O error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found
- Show login dialog when not authenticated yet
- Spring Data Rest supporting json and xml
- @Value annotation not resolved in a class that belongs to dependency jar
- Remove nested _embedded fields while using projections
- How to send Rest GET request that contains "#" value in url parameters?
- How to inject spring bean into Validator(hibernate)
- How to keep a variable in the URL when using Spring LocaleChangeInterceptor
Related Questions in AWS-LAMBDA
- How to get rows count from Amazon DynamoDB using Lambda AWS
- Querying DynamoDB with Lambda does nothing
- undefined is not a function after refactor
- Async AWS Lambda not executed if caller returns too early
- In amazon lambda, resizing multiple thumbnail sizes in parallel async throws Error: Stream yields empty buffer
- How to upload an object into S3 in Lambda?
- How to do image overlay and watermark using node.js in amazon lambda function
- Base64 encode UserData parameter for EC2 RunInstances using AWS Lambda
- AWS Lambda PHP Create Function with Zip
- Triggering a AWS Lambda from a form post
- Zip Files & Folders With No Base Directory
- Dynamically loading jar from arbitrary url
- AWSTask is not instantiable
- AWS Custom Authorizer with request parameters
- Parse OSM PBF in AWS Lambda and S3
Related Questions in DISTRIBUTED-SYSTEM
- Is curator's persistent ephemeral nodes just regular ephemeral with retries?
- Sequential Consistency in Distributed Systems
- Elastic Search: how to move a primary shard?
- Hbase: Understanding difference between smallCompactions and largeCompactions under majorCompaction
- Mnesia - Replicate ram_copy table to disc_only_copy table from another node
- Logical Clocks: Lamport Timestamps
- Lamport’s (Physical) Clock Synchronization Algorithm
- distributed database replication design: efficient network transfer
- Use SimPy to simulate Chord distributed system
- How CreateEntity PDU works?
- How to automatically update server and client side in java
- Distributed database use cases
- Pass map, slice over channel and over network?
- Creating a distributed memory service in Scala
- What is the biggest Couchbase cluster nodes number?
Related Questions in CHRON
- Problems locale language with converting string to dates
- Converting Excel times to POSIXct in r
- How do I do operations with hours greater than 24
- How to get chron to convert a vector of Excel serial dates
- R data.table: Selecting minimum value of chron within group
- Creating and appending csv files
- How to aggregate tweets per minute
- Overcome tibble error: Error: All columns in a tibble must be vectors. x Column `solar.time` is NULL
- xset in BASH script does not work under Cron
- Finding previous month end date
- format - display fractional time data as hh:mm:ss R
- adding hours and minutes to 24 hour time in R
- Missing functions from chron package
- How to programmatically ad a character to a string in R
- How to convert a chron object to a numerical object of seconds since an origin in R
Related Questions in SQSLISTENER
- How do I mock simpleMessageListenerContainer during the test cases
- How to use AWS SQSExtendedClient library to make it work asynchrously using JMSListener java
- Spring boot SQS listener makes message visible if error/exception in processing
- 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
- Single SQS to handle multiple types of message or having one sqs queue for each message type
- Spring Boot 3.0.0, SQS: java.lang.ClassNotFoundException: org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver
- Pause spring SqsListener to pull messages from queue
- High availability in AWS SQS
- How to consume messages from a queue
- Disable SqsListener on specific instances
- Checking if AWS SQS message was received by queue and it is pending to read by listener or already read by listener
- Dynamically modify SQS queue to an @SqsListener method at runtime?
- @SqsListener Not consuming the messages in the queue
- For @sqslistener, value pass from environment variable other than .yaml file
- Running chron job on a single instance of spring service deployed on aws
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)
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?
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.