How can I have RabbitMQ run just once on first message send? - rabbitmq

I'm really new to Rabbit and I am not sure how to search for the exact terms related to this question or what is the best way to execute this
I have a task that gets called when a user reaches a page. I just want that page to get run one time for that day. If more people reach that page, then the task is not executed since it already did. If no one ever goes to that page, then the task is never run.
Can someone please kindly point me to a direction as to what I should be looking for?

You can store a key in Redis (or any other db) and set it's value with timestamp of the last running task: in each page view you will check that value and compare it to the current timestamp; if it refer to the same day, ignore. If it older than current day, update the value and trigger your task.
If your task consume too much time you can wrap it with a simple small webserver (flash/bottle/..) and your original trigger only http request..

Related

Invalidate span when there's a change in a planning entity

So I hit the wall pretty hard on my current implementation.
I have two planning entities: a machine and a task.
The task has a custom shadow variable which calculates the task start time.
It was all working well, however I needed to add a span when the task cannot start at the calculated time, because there are no employees available ( there's a fixed number of employees per machine )
To implement this last feature, after calculating the start time, if the task couldn't be started at that time it searches for the next available time where there are enough employees for this task to start. It is done by looping through the ordered planned tasks of all machines, and calculating if at the end of that task it has enough employees for this task.
The problem with this is: this span time does not go away if the task it spanned until the end of changes position.
I'll leave an image trying to explain this:
Is there a better way to add these spans? Or if I'm in the right direction, is there a way to make sure optaplanner invalidates the start times and recalculates them when such a move occurs?
Thank you in advance!
Update: I've managed to trigger the update for every entity after one changes, however this gets real slow real fast, but i do not see any other way around this, as if an entity changes it may cause lack of employees on another machine's entity, anyone has something else in mind for this issue?

How to clear object store in Mule 3

In my application I use timestamp to query data. The query use the time of now and that last succes run time. I do this to make sure there is no data will be lost in between. This approach also has drawbacks, of course, which is that if the application has any issue for a long time or will crash, a lot of data has to be retrieved at once. Because the application uses the timestamp of the last success run, of course.
Internally, the application runs like the following. A query is executed based on the timestamp and the received payload is used in a foreach loop. Now during testing I run into the issue that the retrieved data is always the same. Even though I change the value from object store to hard value. I keep getting the same payload. It seems that the value used is from the cache. I tried with the operation "Dispose store" and “Remove” but that doesn't work either. Does anyone know how I can delete the object store cache locally but also on the Privet cloud edition?
Thanks for helping

Run AA 24/7 to process records from a DB (there is a new record every minute)

Looking for best practices here. I need to run AA on all days of the week from 08:00 am for 12 hours. Bot will look for new records in a SQL DB every minute. If there's a new record, it will process it (open a website, fill a form etc). Then it will check again if there's a new record and it will repeat the process.
The idea is to schedule a task to start the bot 8:00 AM. Once task starts bot will query SQL etc, but I need to keep the bot running looking for new records.
For now I am first opening the website where records will be inserted and will keep on looping (to check new records in the DB) as long as the website is opened,but I am sure there are more elegant ways to do this.
Looking forward your comments.
First of all I would like to ask you the SLA for each database refresh. Do you want the web activity to be performed on real-time, or can it wait for some time (like checking every hour or so, and processing all new records)?
Because in your approach I believe there would be continuous DB hits even when there's no new record for a long time, which is not the best of approaches.
An alternative that I would like to suggest is to use some kind of a Message Queue which will monitor the database. Then you can write a listener for this Queue and as soon as there's a new record, your bot can process it.
Let me know your thoughts.
Regards,
Atharva
I think one shortcoming in your approach is that you're keeping your website open all long, even when there's no new record for hours. I agree with what Atharva suggested above, you should only login to website when the operation needs to be performed.
Instead of running AA 27/7, you can write a service or something that will monitor the DB. And when there's a new record, will trigger your AA task in some way.

How to pause Web API ? Is it even possible?

We are facing odd issue.
We have two parts
1. Windows task to update database
2. Web API using same database to provide search results
We want to pause API while Windows task updating the database. So Search results won't be partial or incorrect.
Is it possible to pause API request while database is being updated? Database update take about 10-15 seconds.
When you say "pause", what do you expect to happen to callers? It seems like you are choosing to give them errors instead of incomplete data.
If possible, your database updates should be wrapped in a transaction so consumers get current, complete data until the transaction is committed. Then, the next call will have updated and complete data.
I would hope that transactional processing would also help you recover from errors in your updates. What happens now if something fails part way through an update?
This post may help you: How to Decide to use Database Transactions
If the API knows when the this task is being starting, you can do have the thread sleep for 10 seconds by calling:
System.Threading.Thread.Sleep(10000)

having a script autorun on a web server

sorry if my question is a bit ambiguous, I'll explain what i want to do.
i want to run a game on a webserver. its a turn based game, some of you people might have come across it.
Its a game called mafia: http://mafiascum.net/wiki/index.php?title=Newbie_Guide.
I know how it needs to work in terms of a mysql database a server side scripting language etc etc.
What i am not sure about is whats the best way to get a script to activate when the game starts, and be able to run a script every 3 minutes to update the game status:
once 10 people join the game starts
people vote during a 3 minute period. (votes would be stored in a database)
after 3 minutes a script needs to run to calculate the votes and remove a player
then 1 and a half minutes later the script needs to run again.
This cycle of 3 minutes, 1 and a half minutes need to repeat until a certain condition is met, i.e all players but 2 are dead or something.
when players refresh the page they need to be updated on the games status.
Ive read about sockets, and wonder if this might be a good path to take. would sockets be able to send json back to the clients? so that jquery can then update the client with game results.
Ideally i would like the the front end to be done in jquery and the backend script processing to be done by php or something.
How open would this be? in terms of people trying to cheat by sending attacks such as post variables sqli attacks etc etc.
Its quite a broad question, and i am sure there is more than one approcah so is more than one correct answer, but i would be intrested on peoples thoughts on how they would go about developing it.
Thanks for your time :)
I would simply use a CRON job or similar on the backend to update the status every x seconds as you have suggested.
To trigger a game start, simply fire off a PHP command to set your CRON job running.
This way the timing is controlled behind the scenes on the server, and you are free to update the status of the game using jQuery to your actual players.