Running a python based command line script as cronjob on gcloud - python-3.x

I have a python3 based command line script which does the job of report generation for services running online. I am able to successfully schedule it as a cronjob using crontab and some shell script to run that script on weekly basis.
But now, I wish to update and make this script run as a cronjob on gcloud.
Can you provide me any ideas or references, from where I will be able to achieve that?
Note that platform is restricted to google cloud only.
Thanks!

You can use App Engine Cron Service:
The App Engine Cron Service allows you to configure regularly
scheduled tasks that operate at defined times or regular intervals.
These tasks are commonly known as cron jobs. These cron jobs are
automatically triggered by the App Engine Cron Service. For instance,
you might use a cron job to send out an email report on a daily basis,
or to update some cached data every 10 minutes, or refresh summary
information once an hour.
Create a service like /tasks/summary and schedule it to run each week Monday morning via cron.yaml:
cron:
- description: weekly summary job
url: /tasks/summary
target: beta
schedule: every monday 09:00

Related

Netsuite scheduled script https post fail while other scheduled script run

In NetSuite, we created a scheduled script that will run every day to fetch the bank account information.
For that, we use the HTTPS post method.
After a few months of testing and different customers, we figured out that if we have a customer with no other running script, it is working perfectly but if the customer has too much script running, instead of waiting, we have
SSS_INVALID_HOST_CERT An untrusted, unsupported, or invalid
certificate was found for this host.
The only way is to trigger the script manually at a specific hour like 08:57 to avoid the script running every 15min, 30min, ...
Has someone already had this kind of issue?
Is there a trick to scheduling the script at a precise hour?

How to make a schedule report feature using nodejs cron job ? (problem with aws autoscaling)

I am working on "schedule report" feature but facing a problem because of AWS auto scaling feature.
This is how I am executing this feature:
Step 1: User will provide "hour", "minutes" and "report daily or not flag" as input to backend.
Step 2: Backend will make a cron job, store "cron job id" in database and send reports to user via mail according to cron job schedule.
PROBLEM: If the server shuts down and then restarts; then according to start-up script all cron jobs will be started... now if my server has heavy load then AWS auto-scaling will start and on each EC2 instance start-up script will be executed and the same cron-job will be running on different instances.
Therefore same cron job will be running on different EC2 instances and hence user will receive the same emails multiple times (this is the error iam facing, how to solve this issue)
What I have thought till now: We can store a flag in database , if flag is true then cron job will start else will not start. So if one ec2 instance is running cron job, it will set flag to true then other instances won't start it. But the issue is that how to unset the flag if serve suddenly shuts down or such other case.
I am not able to find answer to such a architectural design based issue on net. Is the above approach practical; if then how to properly do it? What is the best way to implement these kind of architectures? Any help will be great, Thanks!
I have faced the same issue.
You can follow 2 ways:
You can run a separate ec2 instance (with vertical scaling) dedicated for cron job.
you can store instance id and cron job status to match running cron job instance

Is it possible to run a cron job randomly between 3-6 minutes?

I defined a cronjob with the whenever gem for Ruby. This created a cron job for the user that runs a ruby script every 5 minutes. The user is not root and doesn't have root permissions.
I would like to be able to run this job randomly between 3-6 minutes. I'm running this job on CentOS 6.2
I think the best thing you could do is setup cron to run the script every minute, and let the script decide when to actually do it's job.
You can have the random effect by keeping track of When the script was executed for the last time
Just make the script run continuously with a random delay between actions. Put it in cron as #reboot and it will restart when the system does.

Jenkins to monitor external cron jobs

We are using a dedicated Amazon Ubuntu ec2 instance as Cron server, which executed 16 cron jobs at different time intervals i.e, 10 cron jobs in morning 4:15 - 7:15 and the rest # 23:00 - 23:50. I get the results via email. I want to configure something, which shoots email message at the end of they day listing the cron jobs that are executed successfully and the one that failed.
I have a jenkins configured ubuntu instance for auto-building Dev, Beta, Staging & Live environments. Can i add these cron jobs(shell scripts) as external jobs in the jenkins and monitor them. Is it possible?
Definitely possible! You can monitor external cron jobs as described here:
https://wiki.jenkins-ci.org/display/JENKINS/Monitoring+external+jobs
You can also add cron job (-like behavior) to Jenkins by creating a freestyle software project and add "Execute shell" as build process.
It's a bit more convenient since you can also trigger the execution via Jenkins ("Build now").
You might be able to combine the Jenkins monitor external job project type with a matrix project. At the very least the former will enable you to monitor the cron jobs individually.
Alternatively you could have the last monitored cron job of the day trigger building a project that checks the status of all the cron jobs (for example by retrieving and comparing the build numbers of the last and the last successful builds) and sends an email accordingly. The email plugin might be useful for the latter.
Check the CPAN or do some web digging for shell or perl script for managing cron jobs and extend its behaviour to do some reporting which you can render using HTML. Alternatively write a servlet and a some function calls to do just that.
This becomes your own standalone monitor application, which can sit in jenkins or deployed independently. If you choose to add it to jenkins, then add the reporting HTML file and its scripts to the container holding deployed web files for jenkins, word of advice place your files and script in a separate container.
Add a hyperlink to jenkins index html which will load your reporter. Now reboot tomcat and go from there.
Another option could be to take a look at Cronitor (https://cronitor.io). It basically boils down to being a tracking beacon that uses http requests to ping when a cron job/scheduled task starts and ends.
You'll be notified if your job doesn't run on schedule, or if it runs for too long/too short, etc. You can also configure it to send alerts to you via email, sms, but also Slack, Hipchat, Pagerduty and others.

Manually start SharePoint timer job

I'd like to invoke a timer job installed on a SharePoint server manually. What would be useful is something along the lines of an stsadm command.
My scenario is, I've deployed a solution with a bunch of features to a customers server. I don't want to wait for the weekly schedule to kick a particular timer job to life. I would like to just punch in a command to get the specific job to run immediately. Obviously in the development enviroment I've got the schedule set for a few minutes but I want to do a test run while I'm on site with the customer.
You can develop a custom command line based tool that gets the job's SPJobDefiniton based on the criteria that identifies your job from the service.JobDefinitions collection. From there you can execute it using the Execute() method.

Resources