Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[3USD] Cron scheduler v.1.0 - Lightweight cron scheduler implementation

Discussion in 'Assets and Asset Store' started by arklay_corp, Jun 15, 2015.

  1. arklay_corp

    arklay_corp

    Joined:
    Apr 23, 2014
    Posts:
    242
    Cron scheduler v.1.0


    Link to the Asset Store: [HERE]

    This asset provides a lightweight implementation in C# of a cron scheduler adapting the code released in Random Sparks Blog.

    Basically cron will allow you to define a trigger to be executed minutely, hourly, daily, weekly, monthly, yearly, on weekends, on a weekday, or on any interval or range of those. It´s a very syntax for job scheduling used in Unix-like systems for decades.

    For more info about the cron syntax and its power, let me refer you to its Wikipedia page.

    A basic cheat sheet:

    In this example the trigger will be fired every Sunday at 2:36 am.

    Every cron schedule contains 5 entries, first for minutes, second for hours, third for days, fourth for months and last one for days of the week.

    Each entry can be:
    • An asterisk: meaning to launch every day, hour, minute…
    • A concrete value:
      • 5: fire at 5am, on May or on Fridays…
    • A range:
      • 1-10: fire each minute from 1 to 10, every day of the day from 1 to 10…
    • A list of values:
      • 1,3,13: fire the trigger at 1am, 3am and 1pm…
    • A divider:
      • */2: on even days, even hours…
      • */5: at 12am, 5am, 10am, 3pm, 8pm…
    • A combination of any of them:
      • 2,3,5-7: on days 2, 3, 5, 6, and 7…
      • 1-10/3: on minutes 1, 4, 7, 10…
      • 2,3,4-10/2: at 2am, 3am, 4am ,6am, 8am and 10am

    It seems complicated but it’s not and almost every configuration can be found on the internet, just googling for example “cron odd hours” (* 1-23/2 * * *).

    The component includes a custom editor with direct access to most used configurations and a quick cheat sheet:




    If you have any doubt, problem or feature request please feel free to ask here.
     
    Last edited: Dec 3, 2015
    ilmario likes this.
  2. arklay_corp

    arklay_corp

    Joined:
    Apr 23, 2014
    Posts:
    242
    Finally in the asset store :)
     
    ilmario likes this.
  3. ilmario

    ilmario

    Joined:
    Feb 16, 2015
    Posts:
    71
    Hey, I just bought this. Surprised there werent other similar cron solutions, this seems very simple and straight forward - though it hasnt been updated for quite a while.
     
  4. arklay_corp

    arklay_corp

    Joined:
    Apr 23, 2014
    Posts:
    242
    Hi @ilmario so far I didn't need to update it, it's being working pretty well so far and, as you say is very simple and straight forward

    Anyway if you found some bug or need some feature to be added, just let me know
     
    ilmario likes this.
  5. ilmario

    ilmario

    Joined:
    Feb 16, 2015
    Posts:
    71
    Glad to hear that @arklay_corp :)

    I found this cron actually after buying your other very impressive asset, Easy Threading.

    Im havent started properly using Easy Threading, but I noticed the "Send Events to Main Thread"-boolean, and I assumed that would work well out of the box since you're the multithreading guru - though multithreading isnt mentioned on the cron asset page.

    Anyway, it seems that checking "Send Events to Main Thread" and defining a onTrigger callback will result in this error:

    Code (CSharp):
    1. get_isPlaying can only be called from the main thread.
    2. Constructors and field initializers will be executed from the loading thread when loading a scene.
    3. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
    4. UnityEngine.Events.UnityEvent:Invoke()
    5. U3D.Cron.CronScheduler:OnCronTrigger() (at Assets/U3D/Cron/CronScheduler.cs:39)
    6. Rlc.Cron.CronObject:ThreadRoutine() (at Assets/U3D/Cron/Rlc.Cron/CronObject.cs:150)
    7.  
    On main thread it works just fine (very nice!).

    In my case I definitely need multithreading for cron .. so, should the multitheading work out of box with the cron asset, or do I need to manually integrate it with Easy Threading?

    (PS: Im using latest Unity 5.5.1)
     
    Last edited: Feb 12, 2017
  6. Gunhi

    Gunhi

    Joined:
    Apr 18, 2012
    Posts:
    300
    could you please create a tutorial video about how to Getting started? even with the Sample scene?
     
  7. arklay_corp

    arklay_corp

    Joined:
    Apr 23, 2014
    Posts:
    242
    I think there is no need for a video for this asset. With the asset you have a readme explaining the basic usage and a sample scene.

    Basically:
    1- add the "CronScheduler" component to any gameobject
    2- configure the component (when do you want the event to be raised; every minute, every day...)
    3- add listeners for the event
     
  8. Gunhi

    Gunhi

    Joined:
    Apr 18, 2012
    Posts:
    300
    Does this work on mobile? My purpose is schedule a list of Local notification in some day of month.
     
  9. arklay_corp

    arklay_corp

    Joined:
    Apr 23, 2014
    Posts:
    242
    It works on mobile, but i think it will not work for you... out of the box. It needs to be executing for the events to be triggered.

    Unless you modify it slightly and use it to retrieve the information to schedule the local notifications
     
  10. Gunhi

    Gunhi

    Joined:
    Apr 18, 2012
    Posts:
    300
    this does seem to work in Background mode (mobile).
     
  11. arklay_corp

    arklay_corp

    Joined:
    Apr 23, 2014
    Posts:
    242
    It should work in background mode until OS decides to kill the app (either after a few minutes or when it needs more memory for other apps) so be very careful with that...
     
  12. ibps13

    ibps13

    Joined:
    Oct 6, 2012
    Posts:
    113
    Hi,

    I use this to schedule a subscription for 1 month, 3monts or 6 months...
    When user start subscription I activate the cron, to call event every month.
    But when user close app, how cron know who is the next month based on the registred date ?
    Does it save the first suscription date ?
    ...

    Thanks for advice
     
  13. arklay_corp

    arklay_corp

    Joined:
    Apr 23, 2014
    Posts:
    242
    you would have to save and restore the internal state, it isn't keep between executions
     
  14. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    Can this be used to tap into an existing time of a Weather System so I can schedule when events happen within a game? For example, Light Objects turn on and off on a specified time (hours, minutes, & seconds) every day based on the current running Weather System time.
     
  15. arklay_corp

    arklay_corp

    Joined:
    Apr 23, 2014
    Posts:
    242
    Hi,

    I could be used, but that's a problem that is easier to solve without using it. (Cron offers more functionality than that, using it just for "an even every day at this time" just adds overhead)
     
  16. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    I see, thanks for the honest and prompt reply. Much appreciated! Actually, I have just found a built-in method within my Weather System that can help me with this. Maybe in the future, I will look into this again if I have the matching requirements. :)