Cron Timer Progress

I have in a site a purchase procedure that through a CRON is subordinated at a pre -established time beyond which the operation is canceled (between 5 and 10 minutes) (0.5,10,15,20,25.30, 35,40,45,50,55 * * * *) and the availability of the updated products again
Everything works without any problem
But what I would like is that in the purchase pages, once the timer has started, a timer progress was visible, to view how long it remains
I don't know if it is possible

When the cron starts, you update some column (Database Update step) in the database to indicate the next time cron will run (NOW + 5 minutes)

And then you get that column on the front-end through a Server Connect. Only thing I don't know is how to make the timer

1 Like

Not familiar but probably setting in your page an action scheduler that loads the server connect that reads the purchases...

It looks a little complicated and I think it is difficult to get a reliable timer. When you are buying a product or service and you know that you have a limited time, you would like to have a timer, but if it is not reliable, it is better perhaps to give up

I think it is better to avoid it IF YOU CAN...

You could go, as you say, with an "estimated time limit" and check for sure on server-side if it s valid.
But in the other case you obviously talk about "live data"...

Think this may help, all it needs is the time of expiry from your Cron job:

What happens if I start a purchase at minute 9 and at minute 10 cron runs?

1 Like

Then I suppose you will end-up with empty hands... No purchace, Save Money!! :grin: :stuck_out_tongue_winking_eye:

1 Like

For each purchase procedure, the CRON starts when the first information is entered and so the count begins.
If for the completion of the purchase information, the times granted by the CRON is respected, you reach the banking form with subsequent payment, the CRON stop
If, on the other hand, the limit time is exceeded, the procedure is stopped, the purchase data is updated and procedure stopped
The current setting works perfectly, but the change of state that determines the cancellation has a variable time

The CRON Activity:
(0.5,10,15,20,25.30, 35,40,45,50,55 * * * *)

The Action CRON calculates the times
{{Now_utc.dateadd ('Hours', 2) .Dateadd ('Minutes', -5)}}

I have timed the CRON of some abandoned purchase procedures and I had further confirmation that the srop of theCRON takes place between 5 and 10 minutes.
So, apart from the difficulty of inserting a timer, I think it is impossible to calculate the precise moment to have a usable timer
Perhaps it could be remedied by inserting a flashing Alert in the pages of the purchase procedure that informs the next reacing the time limit
Maybe green flashing up to 4 minutes 59 seconds, flashing 5 -minute orange up to stop and fixed red time expired
But maybe I want too much

@margio

I tried to simulate what you are trying to do...
I hope I understood correctly.

First of all I started from what @Apple suggested:

BUT REMEMBER:
No matter how beatifull or practical you make it on client-side, on submit you have to check on server-side also the validity of the time elapsed and if the submission is on-time!!

So, I assume that we have a column on the purchase table that it will be filled in with the time that the counter starts (cron).

Is this about what ypu are trying to achieve?

In my test I have left visible the Started_At and Passed_Time columns in the table so you see how it works... (time<300seconds or 5 minutes etc....)
You can hide these columns/values if you want

Here is the code:

<dmx-datetime id="var_DateTime"></dmx-datetime>
    <div class="modal" id="modal_upsPurchase" is="dmx-bs5-modal" tabindex="-1">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Purchase</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <form is="dmx-serverconnect-form" id="frm_upsPurchase" method="post" action="/api/test/purchase_ups" dmx-generator="bootstrap5" dmx-form-type="horizontal" dmx-on:success="notifies1.info('Added...');srvc_getPurchases.load({});frm_upsPurchase.reset();modal_upsPurchase.hide()">
                        <input type="hidden" class="form-control" id="inp_prh_id" name="prh_id" aria-describedby="inp_prh_id_help" placeholder="Enter Prh">
                        <div class="form-group mb-3 row">
                            <label for="inp_prh_Name" class="col-sm-2 col-form-label">Purchase Name</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="inp_prh_Name" name="prh_Name" aria-describedby="inp_prh_Name_help" placeholder="Enter Prh name">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer justify-content-between">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary" dmx-bind:disabled="frm_upsPurchase.state.executing" dmx-on:click="frm_upsPurchase.submit()"><span class="spinner-border spinner-border-sm" role="status" dmx-show="frm_upsPurchase.state.executing"></span>Save changes</button>
                </div>
            </div>
        </div>
    </div>
    <div class="container">
        <div class="row mt-3">
            <div class="col">
                <button id="btn_addPurchase" class="btn btn-info" data-bs-toggle="modal" data-bs-target="#modal_upsPurchase">New purchase</button>
            </div>
        </div>
        <div class="row mt-4">
            <div class="col">
                <table class="table table-bordered table-sm">
                    <thead>
                        <tr class="text-center">
                            <th>Prh</th>
                            <th class="w-100">Prh name</th>
                            <th class="text-nowrap">Prh started at</th>
                            <th class="text-nowrap">Passed time</th>
                            <th class="text-nowrap">Symbol</th>
                            <th class="text-nowrap">Start</th>
                        </tr>
                    </thead>
                    <tbody is="dmx-repeat" dmx-generator="bs5table" dmx-bind:repeat="srvc_getPurchases.data.query" id="tableRepeat1">
                        <tr class="align-middle">
                            <td dmx-text="prh_id"></td>
                            <td dmx-text="prh_Name"></td>
                            <td dmx-text="prh_StartedAt.formatDate('H:mm:ss')" class="text-center"></td>
                            <td dmx-text="prh_StartedAt?(prh_StartedAt.secondsUntil(var_DateTime.datetime)+'s'):''" class="text-center"></td>
                            <td class="text-center align-middle">
                                <i class="fas fa-spinner fa-lg" dmx-class:text-success="prh_StartedAt.secondsUntil(var_DateTime.datetime)&lt;300" dmx-class:text-warning="(prh_StartedAt.secondsUntil(var_DateTime.datetime)&gt;=300)&amp;&amp;(prh_StartedAt.secondsUntil(var_DateTime.datetime)&lt;600)" dmx-class:fa-spin="prh_StartedAt.secondsUntil(var_DateTime.datetime)&lt;600" dmx-class:text-danger="prh_StartedAt.secondsUntil(var_DateTime.datetime)&gt;=600" dmx-show="prh_StartedAt"></i>
                            </td>
                            <td>
                                <form id="frm_purchase_Start" is="dmx-serverconnect-form" method="post" action="/api/test/purchase_start" dmx-on:success="notifies1.info('Started...');srvc_getPurchases.load({})">
                                    <input id="ins_prh_id" name="prh_id" class="form-control" dmx-bind:value="prh_id" type="hidden"><button id="btn_startPurchase" class="btn btn-primary" type="submit" dmx-bind:disabled="state.executing">Start</button>
                                </form>

                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

Here is the creation of the purchases (only the name, startedAt is null):

And here is the simulation of the cron start (update column startedAt -> DateTime) that in my test is triggered when the start button is clicked

Thanks, I have to study it a bit but it seems like a good starting point to make it work correctly. Naturally, for it to be useful, the animated progress should be unique and change color automatically, upon reaching a certain number of minutes, even if at that moment the buyer is not operating on a page of the purchase procedure
Thanks I'll try

1 Like

Yeah @Marzio,

The only thing that is cruisial and important (beside to showing the circle loading symbol in different color depending on time elapsed) is the cron process providing the time_started field to the client-side.
Then , if we have a single DateTime field (time_started) from the server-side, the rest is easy...
Just an auto handling procedure using a DateTime component on Client-side (your page) and some css (dmx-class).

Please copy the code I provided and test it in a test page to see the result.
Then you can just adjust the cron proccess to it

A preliminary question
I created a timer field minutes in the database whose value is saved at the first step of the purchase procedure.
What I'm wondering is: for the use I want to make of it, is it better to save the current time (like example 08:38:00) or is it better to start it (00:00:00)?
Schermata 2024-06-23 alle 19.09.21

Leave the current time...
As a matter of fact you don't even to show/output that time on your page (table).
It is just nesseccary for doing the calculation of time elapsed...
You must have a strarting time in order to calculate the difference from the DateTime components's currect time

Thinking about it, if I'm not completely mistaken, as the Crono is set up I think it is possible to determine the exact time for the conclusion of the Cron (in minutes and seconds)
It should be thus 3 examples
I err?

1 example
Timer Start = 04:12 mm/SS
Timer stop = (05:00 - 04:12) + 05:00
2 Example
Timer Start = 35:23 mm/SS
Timer stop = (36:00 - 35:23) + 05:00
3 Example
Timer Start = 42:23 mm/SS
Timer stop = (05:00 - 43:23) + 05:00

I can't understand...

Can you translate the cron start to a DateTime field and send it on client-side?
That's all you need I think...

What I think can be done is, save in the time of departure of the purchase procedure, two datetime fields
1 datatime now (minutes and seconds)
1 Datetime Stop (calculated according to the Datetime Start)
The calculation is not simple but I think it can be done with some attention
At this point, we should be aware of how many minutes and seconds it will last the Cron count from the moment of starting purchase
It would then be enough to set a timer, assuming that it can be done, which indicates in the pages of the purchase the approach of the time time.

Dear @Marzio,

Or I haven't understood at all what you want to achieve :blush:, or you have been confused...

Let me explain my point of view based on what I understood:

  1. You want in a purscahe list to trigger a counter on individual purchases.
  2. From the moment is is triggered, a counter will be shown at the user on client-side and inform him (with some visual signing, circle symbol/ red-orange-green - css rules)
  3. After the user have triggered the counter for first time, there will be a limit (eg 10 minutes) that he will be able to procceed to the purchase. After that limit the purchase cannot be completed.

So, for all this to work, the way I think it, you just need that start_counter DateTime field on server-side, this must be available on client-side (through your query probably) and then a DateTime component on client side to calculate the differnce of time elapsed based on the start_counter query field...

As a matter of fact, I don't even see the reason to have a cron... Unless the cron is used for something else at the next step that you haven;t mentioned to us...

Note:
The calculation of the time elapse will always be done

  • based on seconds
  • using the .secondsUntil() formatter

AT ANY CASE the final check of the elapsed time will be done on server-side for security reasons., before the final completion of the purchase.

I hope I got it right...

Perhaps it is better to clarify how the purchase procedure is set
Now it is not possible for me. Later I answer you

1 Like