Laravel . Cron vs Queue - laravel

Hello fellow programmers. I google it before posting! Still confused about .
So here is the idea.
Users are planning post to be posted on their social media (concrete time ).
They can change post time even 2 minutes before . Cron would work as expected if it run every minute ,but it seems old solution. On the other hand queue works different (as far as I get) , trying to make better performance which means if there are high number of requests it will not post !!
Is there anything I am missing???
Thanks in advance

I personally prefere old and reliable concepts over new and unreliable one.
About cron - I did set it to run regularry user script (under the user account) and then user can modify that script how often he wants and cron runs it regularry without need for reloading configuration. And the user script can do anything user can - so it can check if time is larger than some value and some unsent messages are pending and eventually send everything needed. So even if it fails send on scheduled time (maybe server down or anything else), it would be send next time the cron hits (maybe every minute)

Related

joomla scheduled task run every second

how can I set a scheduled task that run every second on Joomla website?
I saw different extensions but they make only every minute, like minimum threshold.
Any idea?
If you do this with a plain extension you need enough traffic to trigger the task every second. Even then this would be unreliable. The best way to do this is using a CRON job directly on your web server. This CRON job can call a CLI script or a URL on your server.
https://en.wikipedia.org/wiki/Cron
Here are some useful pages to generate the necessary task entry:
https://crontab.guru/
http://crontab-generator.org/
If you want to run it every second you might want to check this:
Running a cron every 30 seconds
There are funny solution like using sleep to increase the cron time resolution. In addition there is a tiny script in one of the answers which might help as well.
Using a Joomla extension is not reliable at all, since someone must visit the actual website for the (fake) cron to run. So, this whole cron thing when it's a Joomla extension really depends on the traffic of your website, which makes it very unreliable especially if you are developing a mission critical functionality.
Your best option is to use a Linux cron, which cannot run every second, as the minimum for a cron to run is every minute. Any solution requiring the use of sleep or a for loop is not reliable - especially when you take into consideration that you want to run something every second. All the solutions on the Internet for running a cron every second (or less than a minute) are half baked and completely unreliable. In short, you cannot run a cron every second reliably.
An imaginary solution is to have 60 servers, each server is behind the other by 1 second, and then you run the cron from each of these servers every minute. It is important that all these servers are on the same network to prevent any lag.

How do I check to see if a job is in the Laravel queue?

Here's the situation:
I have a Laravel 4.2 application that retrieves (from a third party API) an asset. This is a long-lived asset (it only changes once every 12-24 hours) and is kind of time consuming (a large image file). I do cache the asset, so the impact has been more or less minimized, but there's still the case where the first person who logs in to my application in the morning has to wait while the application loads the asset for the first time.
I have set up a job which will be queued up and will run every eight hours. This ought to ensure that the asset in the cache is always fresh. It works by re-enqueueing the job for eight hours later after it runs.
The problem is this: I'm about to deploy this job system to production & I'm not sure how to start this thing running for the first time.
Ideally, I'd like to have an administration option where I have a button which says "Click here to submit the job", but I'd like to make it as foolproof as possible & prevent people (I'm not the only administrator) from submitting the job multiple times. To do this, however, the application would need to check & see if the job is already in the queue. I can't find a way to do that in an implementation-independent way (I'm using redis, but that may change in the future).
Another option would be to add an artisan command to run the initial process. That way I could deploy the application, run an artisan command, and forget about it.
So, to recap, I have two questions:
Is there a way to check a queue to see what jobs are in there?
Is there a better way to do this?
Thanks
When a job is in laravel queue, it will be saved in jobs table, so you can check by DB.
If it's guaranteed to be the only thing ever in the queue, you could use something like:
if (Queue::size() === 0) {
Queue::push(...);
}
You would need to run the php artisanqueue:listen in the terminal.
Here is the complete documentation if you want to learn more about:
https://laravel.com/docs/5.2/queues#running-the-queue-listener
You can use the Laravel Telescope package.
Laravel Telescope is an elegant debug assistant for the Laravel framework. Telescope provides insight into the requests coming into your application, exceptions, log entries, database queries, queued jobs, mail, notifications, cache operations, scheduled tasks, variable dumps and more. Telescope makes a wonderful companion to your local Laravel development environment.
(Source: https://laravel.com/docs/7.x/telescope)

Using ruby and sinatra how can I schedule a script to run (at an unpredictable time) in the future?

I am designing a reminder type app. Somebody enters into a form, for example, "call me at such and such a time on such and such a day in the future to remind me of something".
This is put into a postgres database. Obviously lots of people (hopefully) will be doing this and scheduling different things at different times in the future.
So, my question is how can ensure that my app checks the database for things it has to do at the right time? Can I:
a) should I, when the entry is made, create an automated script to execute at the time necessary to perform the reminder function? If so, how?
b) get my app to check the database every minute, again if so how? This would seem a huge waste of resources.
Sorry I cannot provide any code for this but I have no idea where to begin. all help gratefully received.
Thank you!
You might wanna use a background job framework like Sidekiq. Sidekiq supports scheduled jobs like this:
Notifier.perform_at(a_time_object, message_to_send)
It seems like Sidekiq also works with Sinatra.
For that particular task I prefer whenever https://github.com/javan/whenever

python3 Auto-logout after certain hour has passed

I have server application written in python3. It stores date and time of logins and logouts in sqlite3 database. What I need it to do is to check if a certain hour has passed eg. 23:00 and then write to database logout time eg. 24:00:00 to those users that haven't loged out yet (because at 23:00 it's obvious that they forgot to logout) . I don't really know how to code this.
Edit:OK I'll specify my question maybe I wrote it too general, I don't really want it to write somebody for me just a hint how to start. How is possible trigger function after certain hour has passed.
Depends how this program is being run. If it is only running when the user does something (such as a web app, which serves a request, then terminates), you might need to create another job which is run by say cron (in the unix world) which would fire off at 23:00 and see if there's anyone who's been logged on for 10+ hours but hasn't had recent activity. If on the other hand the server program is constantly running, you could look into something like the threading.Timer class to run a method at a specified time.

Scheduling Jobs On web server

We Want to Create an online game like this.I think that ,this type of games have a scheduling software on web server. For Example : Player Click to create a resource And resource creation will be take a moment like 20 Minutes.(Every resource creation time will be different). This message will send to web server application but this message will not processed at same time for example must be processed after 20 Minutes. The web server application after getting the message must be put the order in the Queue.
We have Some big problems :
1- The Jobs must be complete by the web server application Even the player Exit the Game. I think that we must create something like Windows service on Web Server. Can we do it? or Is there a better way?
2- The Second problem depended on problem 1 .Because we will have many Jobs (every player can create 20,30 Jobs in every Loggin and we will have thousands of users) , So Our Scheduling System Must be Work On time . it's possible that , there is 100 , 1000 jobs in a same second , if application Can't Done Jobs in him Second will be use the next second Time and the next second jobs will shift to next second and etc. How We can do for this problem ?
Platform : .Net 3.5 On Windows 2003 Web server
Cheers
Asad Safari
Agile Coach , Scrum Master
On unix, use cron to schedule a script to run every minute - the script then handles all the jobs.
http://en.wikipedia.org/wiki/Cron
Well the specific answer would depend on which technology/language/platform you're using. In java, check the scheduling services provided by Quartz to schedule jobs; and check JMS/MDBs to implement the asynchronous event processing you mention in question 2.
I think my answer won't exactly fit your question but it will solve your problem. Both points at once.
First at all, why do you want to automatize the execution of this events? As far as I understand, you need to give the player access to his resource if and only if he created the resource an especific time ago.
Well, this is my solution:
Insert a field in your resource model class named usable_since or something like that and, when the player create his resource, just set it the value of this field to the current time plus the desired waiting time.
In this way you beat the two problems:
the resource will be usable even if the player gets offline and
you just won't need to set up so big job handler, even with a million users.
I hope it helps. I wish you the best luck in developing the game. Make it fun!
I had a somewhat similar question, as I'm also developing an application which relies on server-side scheduling: Job-Scheduling in Play! Framework. I use the Play Framework (Java) and it works like a charm; except I have no experience in how many jobs can be scheduled concurrently without bringing the server to its knees.

Resources