Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8150207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:00:28+00:00 2026-06-06T15:00:28+00:00

Is there any javascript alternative to Cronjob? The thing is, my boss doesn’t want

  • 0

Is there any javascript alternative to Cronjob?

The thing is, my boss doesn’t want to use CronJob anymore for daily executions and told me that if we can do it with javascript instead of CronJob.

I wrote a php+javascript code. It basically collects the daily tasks data (which .php file to execute, what is the time interval etc.) from the database and put them in an object.

Then,

<script>
    function mainFunc(){    
        for(var i=0; i<sizeOfJobs(); i++){ //traverse in the object
            currentDate = new Date();
            //if any of the jobs execution time has come, execute it           
            if(jobs[i]['next_run'] <= currentDate){ 
                $.ajax({
                    url: jobs[i]['file_location'] ,
                    async: false, //this is another question, look below please
                    success: function(data){
                        //after the finish, set next_run and last_run                   
                        currentDate = new Date();                    
                        jobs[i]['last_run'] = currentDate;
                        var nextRun = new Date();
                        nextRun.setTime(currentDate.getTime() + (jobs[i]['interval'] * 60 * 1000));  
                        jobs[i]['next_run'] = nextRun;                        

                    }
                });            
            }                    
        }
        //repeat

        //currently 10 sec but it will increase according to jobs max runtime        
        setTimeout(mainFunc,10000); 
    } 


        $(document).ready(function(){
            setTimeout(mainFunc,10000);        
        })
</script>

So, I use this code. It works fine for basic jobs but there will be a huge jobs which will take 10+ min to finish (like deleting and refilling a db table with thousands of rows)

  • Is it safe?
  • Should I set “async” value to false or not?
  • I’m aware of the situation that there could be jobs which has to execute at the same time and if I set async false, every job needs to wait to finish the previous job etc. so I need to set setTimeout value to total max runtime of all the jobs.
  • If I set it true what it could be happen? My fear is, if a job can’t finish before setTimeout interval, it’s next_run will not be set and it will automatically re-execute. so should I set next_run value before the ajax call?

Back to the main topic, should I need to do all of this? Is there a better solution or library? (I googled but couldn’t find anything useful.)

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:00:29+00:00Added an answer on June 6, 2026 at 3:00 pm

    First of all, in my professional opinion, your boss is crazy 🙂

    Having said that, here’s some changes you can make to address your fears:

    1. Create an array of job_execution_slots with the same length as your jobs array; initialize to null values.

    2. Before you do $.ajax() you check whether the job_execution_slots[i] is “taken” (not null).

    3. When the slot is empty, you do job_execution_slots[i] = $.ajax({...}) and make sure it’s set to async: true; keeping the reference also allows you to “kill” a job by stopping the AJAX request.

    4. In your AJAX completion handler you do job_execution_slots[i] = null;

    This basically serializes the execution per job.

    Let me know if this makes sense to you; I can supply further details upon demand 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any javascript function that can encrypt data: For example i want to
is there any Drupal module to display an alternative page in case Javascript is
I wanted to ask if there is any alternative to JavaScript/AJAX. My goal is
Is there any Scala like alternative to JavaScript? I'm looking for language with: Embeded
Is there any JavaScript/jQuery library for creating step-by-step forms? It's better if it has
Is there any Javascript library that could force an HTML node (mostly images and
is there any javascript library that provides me with a custom event as soon
Is there any javascript algo that i can used to check for a website
Is there any javascript function, to parse the first line of the http header?
is there any JavaScript / jquery library to turn an input into a select

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.