How do I tirgger a function based on time that is stored in my DB?










0















I have a booking API which creates sessions in my DB with one of the columns being scheduled check-in time. I need a functionality which auto checks in the user based on the scheduled check-in time. How do I go about it? The only solution I can think of is running a time-based job scheduler every minute which checks in all the user scheduled for that minute. Is there any better way to achieve this?










share|improve this question






















  • Which DB is it? Source code of the function?

    – michaeak
    Nov 13 '18 at 7:19











  • What did you try to invoke the function and what where your errors?

    – michaeak
    Nov 13 '18 at 7:19











  • what technology is the booking API using?

    – michaeak
    Nov 13 '18 at 7:20











  • @michaeak DB is MySQL and the API is written in Java. There are no errors, I have not implemented it yet. I wanted to make sure if scheduler is the right approach for this.

    – saket agarwal
    Nov 13 '18 at 12:08
















0















I have a booking API which creates sessions in my DB with one of the columns being scheduled check-in time. I need a functionality which auto checks in the user based on the scheduled check-in time. How do I go about it? The only solution I can think of is running a time-based job scheduler every minute which checks in all the user scheduled for that minute. Is there any better way to achieve this?










share|improve this question






















  • Which DB is it? Source code of the function?

    – michaeak
    Nov 13 '18 at 7:19











  • What did you try to invoke the function and what where your errors?

    – michaeak
    Nov 13 '18 at 7:19











  • what technology is the booking API using?

    – michaeak
    Nov 13 '18 at 7:20











  • @michaeak DB is MySQL and the API is written in Java. There are no errors, I have not implemented it yet. I wanted to make sure if scheduler is the right approach for this.

    – saket agarwal
    Nov 13 '18 at 12:08














0












0








0








I have a booking API which creates sessions in my DB with one of the columns being scheduled check-in time. I need a functionality which auto checks in the user based on the scheduled check-in time. How do I go about it? The only solution I can think of is running a time-based job scheduler every minute which checks in all the user scheduled for that minute. Is there any better way to achieve this?










share|improve this question














I have a booking API which creates sessions in my DB with one of the columns being scheduled check-in time. I need a functionality which auto checks in the user based on the scheduled check-in time. How do I go about it? The only solution I can think of is running a time-based job scheduler every minute which checks in all the user scheduled for that minute. Is there any better way to achieve this?







java cron






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 7:18









saket agarwalsaket agarwal

13




13












  • Which DB is it? Source code of the function?

    – michaeak
    Nov 13 '18 at 7:19











  • What did you try to invoke the function and what where your errors?

    – michaeak
    Nov 13 '18 at 7:19











  • what technology is the booking API using?

    – michaeak
    Nov 13 '18 at 7:20











  • @michaeak DB is MySQL and the API is written in Java. There are no errors, I have not implemented it yet. I wanted to make sure if scheduler is the right approach for this.

    – saket agarwal
    Nov 13 '18 at 12:08


















  • Which DB is it? Source code of the function?

    – michaeak
    Nov 13 '18 at 7:19











  • What did you try to invoke the function and what where your errors?

    – michaeak
    Nov 13 '18 at 7:19











  • what technology is the booking API using?

    – michaeak
    Nov 13 '18 at 7:20











  • @michaeak DB is MySQL and the API is written in Java. There are no errors, I have not implemented it yet. I wanted to make sure if scheduler is the right approach for this.

    – saket agarwal
    Nov 13 '18 at 12:08

















Which DB is it? Source code of the function?

– michaeak
Nov 13 '18 at 7:19





Which DB is it? Source code of the function?

– michaeak
Nov 13 '18 at 7:19













What did you try to invoke the function and what where your errors?

– michaeak
Nov 13 '18 at 7:19





What did you try to invoke the function and what where your errors?

– michaeak
Nov 13 '18 at 7:19













what technology is the booking API using?

– michaeak
Nov 13 '18 at 7:20





what technology is the booking API using?

– michaeak
Nov 13 '18 at 7:20













@michaeak DB is MySQL and the API is written in Java. There are no errors, I have not implemented it yet. I wanted to make sure if scheduler is the right approach for this.

– saket agarwal
Nov 13 '18 at 12:08






@michaeak DB is MySQL and the API is written in Java. There are no errors, I have not implemented it yet. I wanted to make sure if scheduler is the right approach for this.

– saket agarwal
Nov 13 '18 at 12:08













1 Answer
1






active

oldest

votes


















0














If it is likely that there is some work every minute, a scheduled job is not that bad. And even if it is not that likely using e constant scheduling interval might be a adequate choice because it is very reliable and usually has a better worst case behavior when many items are ready (because of the roughly constant load).



But the concept "every minute" has some lack. First of all if the job does not run once events in this minute will be lost forever. And if the job takes more than one minute to complete similar problems may arise.



So a better concept is, to execute all items not yet processed with a check-in time up to now, once the job is running. This will safely fall on its feet in case of some incidents.




However, if you want event based execution, i.e. no running job until an item is ready to be processed, you will necessarily need some kind of daemon running in background which schedules the tasks when ready. Some databases have built-in schedulers that can do this job. The Unix command at may do the job as well. (Be aware of time zone issues.)



So assuming you have some daemon that can execute a job at a given time then you need to feed this daemon. Every time a database update causes the next check-in time to change you need to adjust the time of the next job to start. A database trigger might be used for this purpose. But you need to be aware of race conditions here because concurrent updates may trigger in parallel. You also need to take care about lost starts because of some unexpected system failure or for whatever reason. I.e. some kind of monitoring is required.



I would not recommend to start a new job for every item to avoid the above complexity because this might cause excessive resource usage. And furthermore it requires even more monitoring.




Conclusion



Unless there are good reasons not to do so a cyclic scheduled job that checks for work is a simple and reliable solution.



The more complex way to schedule only when there is something to process is recommended if power consumption is an issue and/or the scheduling interval needs to be very small to hit the scheduling time very exactly. E.g. the OS kernel uses this technique to avoid unnecessary wake-ups of the CPU, but here we are talking about an accuracy within the milliseconds range.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275752%2fhow-do-i-tirgger-a-function-based-on-time-that-is-stored-in-my-db%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    If it is likely that there is some work every minute, a scheduled job is not that bad. And even if it is not that likely using e constant scheduling interval might be a adequate choice because it is very reliable and usually has a better worst case behavior when many items are ready (because of the roughly constant load).



    But the concept "every minute" has some lack. First of all if the job does not run once events in this minute will be lost forever. And if the job takes more than one minute to complete similar problems may arise.



    So a better concept is, to execute all items not yet processed with a check-in time up to now, once the job is running. This will safely fall on its feet in case of some incidents.




    However, if you want event based execution, i.e. no running job until an item is ready to be processed, you will necessarily need some kind of daemon running in background which schedules the tasks when ready. Some databases have built-in schedulers that can do this job. The Unix command at may do the job as well. (Be aware of time zone issues.)



    So assuming you have some daemon that can execute a job at a given time then you need to feed this daemon. Every time a database update causes the next check-in time to change you need to adjust the time of the next job to start. A database trigger might be used for this purpose. But you need to be aware of race conditions here because concurrent updates may trigger in parallel. You also need to take care about lost starts because of some unexpected system failure or for whatever reason. I.e. some kind of monitoring is required.



    I would not recommend to start a new job for every item to avoid the above complexity because this might cause excessive resource usage. And furthermore it requires even more monitoring.




    Conclusion



    Unless there are good reasons not to do so a cyclic scheduled job that checks for work is a simple and reliable solution.



    The more complex way to schedule only when there is something to process is recommended if power consumption is an issue and/or the scheduling interval needs to be very small to hit the scheduling time very exactly. E.g. the OS kernel uses this technique to avoid unnecessary wake-ups of the CPU, but here we are talking about an accuracy within the milliseconds range.






    share|improve this answer



























      0














      If it is likely that there is some work every minute, a scheduled job is not that bad. And even if it is not that likely using e constant scheduling interval might be a adequate choice because it is very reliable and usually has a better worst case behavior when many items are ready (because of the roughly constant load).



      But the concept "every minute" has some lack. First of all if the job does not run once events in this minute will be lost forever. And if the job takes more than one minute to complete similar problems may arise.



      So a better concept is, to execute all items not yet processed with a check-in time up to now, once the job is running. This will safely fall on its feet in case of some incidents.




      However, if you want event based execution, i.e. no running job until an item is ready to be processed, you will necessarily need some kind of daemon running in background which schedules the tasks when ready. Some databases have built-in schedulers that can do this job. The Unix command at may do the job as well. (Be aware of time zone issues.)



      So assuming you have some daemon that can execute a job at a given time then you need to feed this daemon. Every time a database update causes the next check-in time to change you need to adjust the time of the next job to start. A database trigger might be used for this purpose. But you need to be aware of race conditions here because concurrent updates may trigger in parallel. You also need to take care about lost starts because of some unexpected system failure or for whatever reason. I.e. some kind of monitoring is required.



      I would not recommend to start a new job for every item to avoid the above complexity because this might cause excessive resource usage. And furthermore it requires even more monitoring.




      Conclusion



      Unless there are good reasons not to do so a cyclic scheduled job that checks for work is a simple and reliable solution.



      The more complex way to schedule only when there is something to process is recommended if power consumption is an issue and/or the scheduling interval needs to be very small to hit the scheduling time very exactly. E.g. the OS kernel uses this technique to avoid unnecessary wake-ups of the CPU, but here we are talking about an accuracy within the milliseconds range.






      share|improve this answer

























        0












        0








        0







        If it is likely that there is some work every minute, a scheduled job is not that bad. And even if it is not that likely using e constant scheduling interval might be a adequate choice because it is very reliable and usually has a better worst case behavior when many items are ready (because of the roughly constant load).



        But the concept "every minute" has some lack. First of all if the job does not run once events in this minute will be lost forever. And if the job takes more than one minute to complete similar problems may arise.



        So a better concept is, to execute all items not yet processed with a check-in time up to now, once the job is running. This will safely fall on its feet in case of some incidents.




        However, if you want event based execution, i.e. no running job until an item is ready to be processed, you will necessarily need some kind of daemon running in background which schedules the tasks when ready. Some databases have built-in schedulers that can do this job. The Unix command at may do the job as well. (Be aware of time zone issues.)



        So assuming you have some daemon that can execute a job at a given time then you need to feed this daemon. Every time a database update causes the next check-in time to change you need to adjust the time of the next job to start. A database trigger might be used for this purpose. But you need to be aware of race conditions here because concurrent updates may trigger in parallel. You also need to take care about lost starts because of some unexpected system failure or for whatever reason. I.e. some kind of monitoring is required.



        I would not recommend to start a new job for every item to avoid the above complexity because this might cause excessive resource usage. And furthermore it requires even more monitoring.




        Conclusion



        Unless there are good reasons not to do so a cyclic scheduled job that checks for work is a simple and reliable solution.



        The more complex way to schedule only when there is something to process is recommended if power consumption is an issue and/or the scheduling interval needs to be very small to hit the scheduling time very exactly. E.g. the OS kernel uses this technique to avoid unnecessary wake-ups of the CPU, but here we are talking about an accuracy within the milliseconds range.






        share|improve this answer













        If it is likely that there is some work every minute, a scheduled job is not that bad. And even if it is not that likely using e constant scheduling interval might be a adequate choice because it is very reliable and usually has a better worst case behavior when many items are ready (because of the roughly constant load).



        But the concept "every minute" has some lack. First of all if the job does not run once events in this minute will be lost forever. And if the job takes more than one minute to complete similar problems may arise.



        So a better concept is, to execute all items not yet processed with a check-in time up to now, once the job is running. This will safely fall on its feet in case of some incidents.




        However, if you want event based execution, i.e. no running job until an item is ready to be processed, you will necessarily need some kind of daemon running in background which schedules the tasks when ready. Some databases have built-in schedulers that can do this job. The Unix command at may do the job as well. (Be aware of time zone issues.)



        So assuming you have some daemon that can execute a job at a given time then you need to feed this daemon. Every time a database update causes the next check-in time to change you need to adjust the time of the next job to start. A database trigger might be used for this purpose. But you need to be aware of race conditions here because concurrent updates may trigger in parallel. You also need to take care about lost starts because of some unexpected system failure or for whatever reason. I.e. some kind of monitoring is required.



        I would not recommend to start a new job for every item to avoid the above complexity because this might cause excessive resource usage. And furthermore it requires even more monitoring.




        Conclusion



        Unless there are good reasons not to do so a cyclic scheduled job that checks for work is a simple and reliable solution.



        The more complex way to schedule only when there is something to process is recommended if power consumption is an issue and/or the scheduling interval needs to be very small to hit the scheduling time very exactly. E.g. the OS kernel uses this technique to avoid unnecessary wake-ups of the CPU, but here we are talking about an accuracy within the milliseconds range.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 7:54









        MarcelMarcel

        875217




        875217



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275752%2fhow-do-i-tirgger-a-function-based-on-time-that-is-stored-in-my-db%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto