Create cron job to run with MySQL - cron

I've got a code that will delete a WordPress post from my database if it contains a certain text:
DELETE FROM wp_posts WHERE post_excerpt LIKE "%neuroscience%"
I want to get this to run every hour, but I don't know if I should initiate this within the MySQL platform, or via cPanel. I would prefer the latter so all my cron jobs would be in one place. But the truth is I don't know how to code either!

Why not just CREATE TRIGGER in MySQL itself ?
It will delete the post whenever they occur and if you use BEFORE UPDATE it won't even get into the database.

Related

Running Cron Job on Cpanel for Node.js Project

I have an API built with Express JS and deployed on cPanel. The API has a script, let's say the endpoint looks like this:
/api/v1/cron
When the URL is hit, an SQL query runs and some data is inserted to the database, and no problem with that.
What I want is to automate the process through Cron job. The URL should be hit once every hour so the query will execute and push data to the database.
I have tried with the basic settings and a command like this on cPanel but didn't work:
/usr/local/bin/php -q /home2/{domain}/api/v1/cron
Please note: The API is in subdomain, like: node-api.google.com
I have also tried with node-cron package, but couldn't find a way how to run a script with that.
Either solution will work for me greatly.

Run a schedule function for every user in node js

I need to find the best possible way to do the following task.
I have different users let's say (over 500) and all users have a scheduled function that need to be run twice every day. But if any of the user's phone is off. Then of course that function wont work since its code is written on client side.
now what i want to do is Run a scheduled function in the backend using Node js, but idk how to run that for every user. (note : every user has different schedules). Thats why i wrote that in client side, but with with a possibility of phone might be switched off so its bit off to do that.
What should i do in this scenario? any leads?

Nodejs API architecture cron job

I'm building a REST API with Nodejs with MongoDB as database.
This API only have GET routes to retrieve data. This data is aggregated from others sources via cron job.
I'm not sure how to correctly implement this and what are the best practices.
Do i need to create POST/PUT route to put data in database ?
Do i need to just put data directly in the database ?
Edit : (more informations)
Only the cron jobs would use POST route
The cron jobs are getting data from others REST API and some web scraping.
Is it a good idea to have my cron in the same application with the API, or if I have to make another application to manage my cron jobs and populate my database ?
I suggest creating an API which can be called using an accessKey for updating the data because you would not want to write your mongo db username and password in a shell file.
But if the cron job is a k8s cron job or just a file written in some programming language which can access the db in secure way and is hosted in the same network then you can go ahead with doing it from cron job.
If you'd like to control the data flow entirely through API at this point, creating a POST route would be the way to go. I am not sure how are your GET routes secured - if not at all, consider implementing or at least hard-coding some sort of security for routes that modify your data (oAuth2 or similar).
If you can access the database directly and it's desired, you can just directly insert/update the data.
The second option would be probably quicker, but the first one offers more space for expansion in the future and could be more useful overall.
So in the end, both options are valid, it's up to preference and your use case.

Issue while creating user for a specific database through code in Azure

I am creating a copy of database in Azure through c# code.
Code for creating database:
CREATE DATABASE ABC AS COPY OF DEF
Then I want to create a user in that database so that only that user can access the database. This code executes as soon as the database is created. but while creating a user I get an error:
"failed to update database because the database is read only".
If I stop the execution for 15-20 seconds, then start, it works perfectly, but I don't want to do that.
Can I get some status that the database is created and you can proceed.
Any help would be greatly appreciated.
It appears that you're connecting to your database and executing T-SQL, you may have to use a query against sys.dm_operation_status and find your Create Database command and whether it has completed. There may be an associated REST API if you choose to program this through REST calls, there is a Get Create or Update Server Status call which might fit your scenario.
You will find that the new database will take some time to create and you won't exit that logic instantly in either approach.

standard way of setting a webserver deploy using webhooks

I am working on code for a webserver.
I am trying to use webhooks to do the following tasks, after each push to the repository:
update the code on the webserver.
restart the server to make my changes take effect.
I know how to make the revision control run the webhook.
Regardless of the specifics of which revision control etc. I am using, I would like to know what is the standard way to create a listener to the POST call from the webhook in LINUX.
I am not completely clueless - I know how to make a HTTP server in python and I can make it run the appropriate bash commands, but that seems so cumbersome. Is there a more straightforward way?
Setup a script to receive the POST request ( a PHP script would be enough )
Save the request into database and mark the request as "not yet finished"
Run a crontab and check the database for "not yet finished" tasks, and do whatever you want with the information you saved into database.
This is definately not the best solution but it works.
You could use IronWorker, http://www.iron.io, to ssh in and perform your tasks on every commit. And to kick off the IronWorker task you can use it's webhook support. Here's a blog post that shows you how to use IronWorker's webhooks functionality and the post already has half of what you want (it starts a task based on a github commit): http://blog.iron.io/2012/04/one-webhook-to-rule-them-all-one-url.html

Resources