Author Topic: Scheduled Tasks  (Read 896 times)

Offline Beyond2000

  • Jr. Member
  • **
  • Posts: 52
  • Karma: +7/-1
    • View Profile
Scheduled Tasks
« on: June 27, 2018, 08:06:33 AM »
Good day.
I can do add task to schedule.. but that shedule? it just lay there. Will there be any development in adding a real schedule that we as users of abantecart can set date's times and reocurence?

I see the need as it was asked about a few times in the past.

attached screen shot. It creates the task and then you must manualy start it. Is it possible to create a cronn job from C-Panel to run it and what is the files name and location if possible to run it from C-panel after creation.

Enjoy your day.

Offline eCommerce Core

  • Administrator
  • Hero Member
  • *****
  • Posts: 1596
  • Karma: +92/-1
    • View Profile
Re: Scheduled Tasks
« Reply #1 on: June 27, 2018, 10:39:37 AM »
To have tasks processed based the schedule automatically, you need to set up crontab on your server or run task.php command manually.

See this manual
https://abantecart.atlassian.net/wiki/spaces/AD/pages/15007901/Scheduled+Tasks
“If you’re in the luckiest one per cent of humanity, you owe it to the rest of humanity to think about the other 99 per cent.”
― Warren Buffett

Offline Beyond2000

  • Jr. Member
  • **
  • Posts: 52
  • Karma: +7/-1
    • View Profile
Re: Scheduled Tasks
« Reply #2 on: June 28, 2018, 03:13:25 AM »
Good day

Ok I've figured out how to setup a cronjob. The problem is now in 2 parts.

1st. Wich task.php is the one I must select? (There are a task.php file located in different folders)

2nd. Where will the stock update file be stored, so I can overwrite it accordingly. I can upload the stock file automatic to my webdomain.

Enjoy your day

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1751
  • Karma: +240/-10
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Scheduled Tasks
« Reply #3 on: June 28, 2018, 04:35:20 AM »
Good day

Ok I've figured out how to setup a cronjob. The problem is now in 2 parts.

1st. Wich task.php is the one I must select? (There are a task.php file located in different folders)

2nd. Where will the stock update file be stored, so I can overwrite it accordingly. I can upload the stock file automatic to my webdomain.

Enjoy your day

1. for calls from cron you should to run /public_html/task_cli.php file
for example:
Code: [Select]
/usr/bin/php /path/to/public_html/task_cli.php --task_id=12
2. https://github.com/abantecart/abantecart-src/blob/master/public_html/task_cli.php
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline Beyond2000

  • Jr. Member
  • **
  • Posts: 52
  • Karma: +7/-1
    • View Profile
Re: Scheduled Tasks
« Reply #4 on: June 28, 2018, 04:52:50 AM »
Hi

no1 I understand. This is the file to be run by the cron job.

no2. Must I edit that file with the location of the AbanteCart instalation and also ( i did not read the file completely) the location and name on the webserve where the product update file is located.

This bring me to a question. Must I also put the update mapping file on the webserver (and is it in txt format) and give the location of that file to load the mappipng?


Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1751
  • Karma: +240/-10
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Scheduled Tasks
« Reply #5 on: June 28, 2018, 04:59:40 AM »
You had posted screenshot with task list in your database. You can start one of them via UI. Also you can start it from cron.

To run from cron your should paste command posted above into your crontab file.
Just set option task_id  (see database table tasks)
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline Beyond2000

  • Jr. Member
  • **
  • Posts: 52
  • Karma: +7/-1
    • View Profile
Re: Scheduled Tasks
« Reply #6 on: June 28, 2018, 05:09:41 AM »
Hi
Great now I can do the task automatically.

The last question is. The new stock file. How do I get abantecart to load it automatically? I want to have the price and stock levels updated automatically ( when I go on leave it can still update.)

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1751
  • Karma: +240/-10
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Scheduled Tasks
« Reply #7 on: June 28, 2018, 05:19:25 AM »
The last question is. The new stock file. How do I get abantecart to load it automatically? I want to have the price and stock levels updated automatically ( when I go on leave it can still update.)
you have 2 ways.
1.Just create your own task with it's task-controller that will do what you want. Then call this task via cron.
2.  you can write your own simple php-script and place it upper web-root directory. Inside this script you can connect to database and update price directly inside database.

But i prefer 1st way. Task-controller works in engine scope and you can call models and cache directly.

Also you can save all temporary files inside admin/system/temp directory.
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline Beyond2000

  • Jr. Member
  • **
  • Posts: 52
  • Karma: +7/-1
    • View Profile
Re: Scheduled Tasks
« Reply #8 on: June 29, 2018, 05:03:01 AM »
Hi
I've got the cronjob to run.
Command used: /public_html/shop/task_cli.php run --task_id=79

It was successfull and I got an email with this:

Running: Task ID 79:
array(1) {
 
  • =>

  array(2) {
    ["products"]=>
    array(4) {
      ["sku"]=>
      array(1) {
       
  • =>

        string(13) "6004405011023"
and every item detail.

Then on the next run it failed?
this is the email:

Running: Task ID 79:
Error: Task ID 79 has failed!
Finished running: Task ID 79:


It is the same cronjob nothing changed.
« Last Edit: June 29, 2018, 05:10:26 AM by proteaapteek »

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1751
  • Karma: +240/-10
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Scheduled Tasks
« Reply #9 on: June 29, 2018, 05:07:45 AM »
hm... see the cause in log directory /system/log/
Also check task status and errors.
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline Beyond2000

  • Jr. Member
  • **
  • Posts: 52
  • Karma: +7/-1
    • View Profile
Re: Scheduled Tasks
« Reply #10 on: June 29, 2018, 05:23:11 AM »
I've renamed the log files to old as i only want to have the errors inside. set the cronjob to every minute. ( the stock items is only 7 for testing perpouses) it created new log files but it is empty.
I wonder if the problem is not that it shows on the Scheduled Tasks  as completed. It runs only once from the cronjob if the status shows ready and when completed it do not want to run again. I've tried it 2 times and everytime it run once only.

Ok I've tested. I logged with C-panel onto the database. I've changed the status from 5 (completed ) to 1 ( ready) the cron job run again. Is there a way to have it change the status back to 1 when finnished running or to leave the status alone?
« Last Edit: June 29, 2018, 05:44:10 AM by proteaapteek »

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1751
  • Karma: +240/-10
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Scheduled Tasks
« Reply #11 on: June 29, 2018, 05:55:36 AM »
Is there a way to have it change the status back to 1 when finnished running or to leave the status alone?

usually we'd created tasks with 2 steps. 1st - that makes something and 2nd with finishing. Finishing means some logic related to step 1 result. For example you should to check result code of step 1 and change status to "ready"  again....otherwise send email to admin if failed
Do the same. Put task status change into 2 step. Just create 2nd task-controller and insert it's route into step details (see table task_steps) (or use our core/lib/task_manager.php) up to you
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline Beyond2000

  • Jr. Member
  • **
  • Posts: 52
  • Karma: +7/-1
    • View Profile
Re: Scheduled Tasks
« Reply #12 on: June 29, 2018, 07:44:36 AM »
Hi
Would like to use the task_manager.php file.
I'm very basic in programming. I've tried several options. none wants to work.
When task is completed i want to set the status to ready but fails. I think maby the line 556 on my file that say    '" . (int)$data['status'] . "', I changed the word status to 1 it did not help.

What will be the best place to change the task status back to 1?
From the previous post till now I was the whole time trying to make it work and my knowledge of prgramming is realy very limited. I understand the concepts and word but to write it . I fail everytime.

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1751
  • Karma: +240/-10
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Scheduled Tasks
« Reply #13 on: June 29, 2018, 09:24:55 AM »
ha! found:-)

try to add option --force into your crontab command
i mean /usr/bin/php /path_to/task_cli.php --task_id=** --force
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline Beyond2000

  • Jr. Member
  • **
  • Posts: 52
  • Karma: +7/-1
    • View Profile
Re: Scheduled Tasks
« Reply #14 on: June 29, 2018, 09:36:13 AM »
Hi
Thanks a lot!!! it is working.
Enjoy your day