Where to host your code to run systematically

Discussion in 'App Development' started by TheBigShort, Jan 22, 2020.

  1. TheBigShort

    TheBigShort

    Hey everyone,
    I have code (R of course) that I have running on my PC. Every hour my PC wakes up and runs my .bat file which runs my .R script.

    I don't like the idea of my computer continuously waking up. Some times I come home and my task scheduler ran the code past my end time (lets say 4pm EST).

    What I would like is to host my .R script somewhere on the cloud and have that run every hour between 9am-5pm. I was advised to check out github.com/jhuckaby/Cronicle to complete this task. I am curious to know what you guys do to run your scripts continuously.

    Thanks for your help.
     
  2. guru

    guru

  3. TheBigShort

    TheBigShort

    hey guru

    I think you are familiar with C++ IIRC. I need a program that will run the C++ script every N hours. Lets say you have a simple script

    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
        cout << "Hello, World!";
        return 0;
    }
    I want my instance on AWS to run this at specific time intervals. I am not to sure how to do it.
     
  4. guru

    guru

    yc47ib and lovethetrade like this.
  5. guru

    guru

  6. TheBigShort

    TheBigShort

    I am currently doing windows task scheduler which is what I am trying to move away from.

    It looks like I want to go the approach you took with your C# script.
    Would you mind giving me a brief overview and then I'll fill in the gaps. I am more interested on how you set up the server and how much it's costing you.
     
  7. guru

    guru

    So in my case it's just a console app in C# that loops and waits for various time points. Here is a screenshot:

    upload_2020-1-22_0-52-33.png

    I also record each event's start/end time in a database, and later can review logs.
    I run/host this on my own server at home, so not paying anything externally.
    I do have additional, colocated servers at a web hosting company, but I had to bring them in and install myself, paying only for space, electricity and bandwidth - so it's a different scenario.

    In the past I was renting virtual and dedicated servers from web hosting companies, from $20/month to $200/month. The virtual ones should be sufficient - they'll give you a login to a shared server but it will be virtually separated from other users and will look like your own, and only you'll have access to it. You'll login to it remotely and it will look like fresh installation of Windows where you can run whatever you like.
    I was using this company in the past:
    https://www.ionos.com/servers/vps

    But virtual/VPS servers from Amazon may work just like that. Also Digital Ocean was very popular.
     
    Last edited: Jan 22, 2020
  8. guru

    guru

    And if you want quick C# code, here is my function that waits until specific time:

    static async Task WaitUntil(TimeSpan time)
    {
    DateTime now = DateTime.SpecifyKind(TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")), DateTimeKind.Utc);
    int ms_to_sleep = (int)(time - now.TimeOfDay).TotalMilliseconds + 1000; //Wait until desired time
    if (ms_to_sleep > 0)
    {
    Console.WriteLine(string.Format("{0}. Waiting {1} seconds until {2}", now.ToHH_MM_SS(), (ms_to_sleep / 1000).ToString("0,0"), time.ToString()));
    await Task.Delay(ms_to_sleep);
    }
    }​
     
    Last edited: Jan 22, 2020
  9. TheBigShort

    TheBigShort

    Thanks Guru! I like the idea of storing the run times. For some reason I thought it would be much more complicated. Seems easy enough.
     
    guru likes this.
  10. Heydrrich

    Heydrrich

    1) get a droplet on for example digital ocean or aws for 5$ a month.
    2) you must be able to run c++ on your droplet:
    Run C++ on linux: https://rupinderjeetkaur.wordpress.com/2014/06/20/run-a-cc-program-on-terminal-using-gcc-compiler/
    3a: configure your cronjob
    https://crontab-generator.org/
    3b: create a cronjob
    https://docs.oracle.com/cd/E19253-01/817-0403/sysrescron-72169/index.html


    But why would you need C++, you should be able to run R code directly via cron.
     
    Last edited: Jan 22, 2020
    #10     Jan 22, 2020