Better way to schedule cron jobs based on job orders from php script
While it is possible to use the database as a queue, it is commonly known as an anti-pattern (next to using the database for logging), and as you are looking for:
So any way / package / system to accomplish this behavior?
I use the free-form of your question thanks to the placed bounty to suggest: Beanstalk.
Beanstalk is a simple, fast work queue.
Its interface is generic, but was originally designed for reducing the latency of page views in high-volume web applications by running time-consuming tasks asynchronously.
It has client libraries in the languages you mention in your question (and many more), is easy to develop with and to run in production.
Run a cron job that performs other cron jobs schedules in MYSQL
If you're ok with the minimum cron-job interval, which is one minute, then your approach is good to go. I assume you're storing the on-demand
jobs within one of your database's table, in which case you need to also consider the following:
- you need to mark the
on-demand
jobs asin progress
to avoid the scenarios where anon-demand
job takes more than a minute and is also picked up by the next job - you might also consider retrying failed jobs, or jobs for which the processing script failed (either crashed or was killed by system for whatever reason)
If the on-demand
actions need to be taken care of as soon as possible, and you also want to take care of the above two items, then you might consider a job scheduling approach, like using RabbitMQ
. This approach has a bit more steep learning curve then the cron
-based one, however the great advantage is that once you schedule the job you don't need to care much about it, except telling the job scheduler
how to run it.
CronJob not running
Finally I found the solution. Following is the solution:-
Never use relative path in python scripts to be executed via crontab.
I did something like this instead:-import os
import sys
import time, datetime
CLASS_PATH = '/srv/www/live/mainapp/classes'
SETTINGS_PATH = '/srv/www/live/foodtrade'
sys.path.insert(0, CLASS_PATH)
sys.path.insert(1,SETTINGS_PATH)
import other_py_filesNever supress the crontab code instead use mailserver and check the mail for the user. That gives clearer insights of what is going.
Related Topics
How to Get Count of Rows in MySQL Table Using PHP
Correct Way to Use Like '%{$Var}%' With Prepared Statements
MySQLi_Real_Escape_String() Expects Exactly 2 Parameters, 1 Given
Simultaneous Requests to PHP Script
How to Convert a Number to a Word in PHP
How to Get the Error Message For the Mail() Function
Achieve Hierarchy, Parent/Child Relationship in an Effective and Easy Way
Call to a Member Function Prepare() on a Non-Object PHP Help
Nginx Location Configuration (Subfolders)
Error With PHP Mail(): Multiple or Malformed Newlines Found in Additional_Header
PHP Function to Make Slug (Url String)
Pdo Valid Characters For Placeholders
What Kind of String Is This? How to Unserialize This String
How to Remove "Public/Index.PHP" in the Url Generated Laravel
MySQL Prepared Statements With a Variable Size Variable List
Convert Dot Syntax Like "This.That.Other" to Multi-Dimensional Array in PHP