Setting up a cron job with Laravel and AWS - laravel

I have a list of customers' email and I would like to send promos and news every week.
How do I set this up on AWS using Laravel?
What I currently did was using Laravel's queues something like this:
website.com/api/SendScheduledEmail
So far what I have tried is the crontab on Linux but I don't know how can I visit and execute my URL using it.

you can do as per what #eResourcesInc mentioned whereby you add a scheduled command shown below
$schedule->command('command:send_newsletter')
->daily()
->appendOutputTo(storage_path('logs/send_newsletter.log'));
Documentation here: https://laravel.com/docs/5.8/artisan
If your task has the potential to take a long time/or consume alot of resources. Maybe you can try serverless, like running your task as a function in AWS or Aliyun. More info here: https://vapor.laravel.com
Hope it helps.

Related

Laravel: get details about a queue job

How can I get job details from its ID, ex: 866FvqTxVVvi4PmCo7kHmD7u7bHaxCdn
got that id from queue:listen, thanks
There isn't a built in way of doing this through Laravel. It entirely depends upon which queue driver you are using.
For example, if you are using Redis then you would need to use the Redis CLI to search through the database for the appropriate task.

Laravel Scheduler (withoutOverlapping)

I have two apps running on the same server.
Now it seems like when adding withoutOverlapping() to the scheduler job and managing the base cronjob via cron itself, these 2 apps are blocking each other in execution.
Could that be?
Yes, withoutOverlapping only works per application.
Laravel creates a file in the storage folder with a hash of the job. This way, if the file exists, Laravel knows the job is still running. The one application cannot possibly know if the other one is currently running a job because it does not have access to the storage folder of the other application.
If your code looks like the following
$schedule->command('process:queue 0')->everyMinute()->withoutOverlapping();
$schedule->command('process:queue 1')->everyMinute()->withoutOverlapping();
It is because same commands with different parameters might bc considered overlapping.
I.e. the hash of the job will consider only the command signature.

How to email time-out notice from Google Cloud Storage?

I have a gsutil script that that periodically backs up data to Google Could Storage.
The gsutil backup script runs on my local box.
I would like to run a script (or service) on Google Could Storage, that emails a warning to the administrator when no backup has been made in 24 hours.
I am new to cloud services. Please point me in the right direction.
Where would such a script be located? Is there a similar example script?
Thank you.
There's no built-in feature that accomplishes this. However, you could accomplish something like this with another monitor program.
For example, I might edit my backup script such that after successfully completing a backup, it writes the current time to a "last_successful_backup.txt" file. Then, I'd put a cronjob wherever I keep my monitors and alerting systems that would check the "last_successful_backup.txt" file every few hours and set off an alarm if the time it contains is older than 24 hours.
What about to spin up Google VM and send emails from the instance? Using, say, SendGrid, Mailgun, or Mailjet

Start wercker job hourly

I've just started using wercker and I'd like a job to run regularly (e.g. daily, hourly). I realize this may be an anti-pattern, but is it possible? My intent is not to keep the container running indefinitely, just that my workflow is executed on a particular interval.
You can use a call to the Wercker API to trigger a build for any project which is set up already in Wercker.
So maybe set up a cron job somewhere that uses curl to make the right API call?

Schedule to create AMI weekly from a running instance?

I have few servers running on Amazon's EC2 and I would like to backup the image (create AMI) every week (replacing the old image).
Is there any way to automate this?
You should be able to use the command line tools to create an ami. Something like ec2-create-image -n "<image name here>" <your instancId here>. Put that in a cron entry that is scheduled weekly and you are done. You should be able to use the answer to this question to figure out what your instance id is programatically.
You can now use AWS Lambda to create AMIs automatically. The whole setup should be completed in around 10 minutes along with the schedule that you like.

Resources