Table to store data for aimeos job ?

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Table to store data for aimeos job ?

Post by MikaelNazarenko » 02 Oct 2020, 11:34

Hello)

I use Laravel.

I have created aimeos job. This job I added to crontab. But it must perform the task when I press button on back-end side. For this I think to write some data to db, so when cron executes the job - it knows if has to be executed and additional parameters.
But is there existing aimeos table for this ?

User avatar
aimeos
Administrator
Posts: 8636
Joined: 01 Jan 1970, 00:00

Re: Table to store data for aimeos job ?

Post by aimeos » 03 Oct 2020, 07:39

Yes, the madmin_job table stores the information and you can use the job manager to manipulate the entries:

Code: Select all

$manager = \Aimeos\MAdmin::create( $context, 'job' );
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: Table to store data for aimeos job ?

Post by MikaelNazarenko » 03 Oct 2020, 07:47

Thank you! But there is no implemented way in aimeos to interact with jobs from back-end interface ? Or where that madmin_job table is used at all ?

User avatar
aimeos
Administrator
Posts: 8636
Joined: 01 Jan 1970, 00:00

Re: Table to store data for aimeos job ?

Post by aimeos » 03 Oct 2020, 07:53

Guess you want to create an export or something like that.
You have to extend the template to add your button, extend the admin client class by implementing the export() method, use the job manager to write the data needed into the madmin_job table and implement a job controller which reads the entries applicable to the jobs using the job manager, performs the export and writes the resulting file name into the job entry so it will be listed in the dashboard for download.

If you only want to perform an action with no result in the admin interface, you can also use the message queue provided by the context object.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: Table to store data for aimeos job ?

Post by MikaelNazarenko » 03 Oct 2020, 08:15

Ok let me explain what exactly I need. I need to generate pdf files when admin press button on dashboard. Generate them with browser request - is bad I idea. So I already have added button to dashboard (extended view). And I also have created new job controller with run method and so on. And I have set up cron every minute. So cron executes my job every minute. But problem is to tell somehow, so job has to know when button is pressed and job has to generate files + I have to pass some parameters to job when button is pressed. This data I guess to write in some DB table. And then job checks if it has to generate files + job grabs needed parameters from that table. After job is done, when script near finished execution - it will write another state to table like "no needed to generate files".

Also, since cron executes the job every minute, and files generation may take longer, to prevent several same processes, I am going to use next solution:

Code: Select all

$f = fopen('commission-calculation-lock', 'w');
if (flock($f, LOCK_EX | LOCK_NB)) {
       //////////
}
If you could suggest something better solution, please fix me :) Especially now I am wondering the table where to save info..

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: Table to store data for aimeos job ?

Post by MikaelNazarenko » 03 Oct 2020, 11:46

And yes, I noticed, when I add data to madmin_job table - it is shown on dashboard, but my target is not that, I have described my target on above post.

Thank you!

User avatar
aimeos
Administrator
Posts: 8636
Joined: 01 Jan 1970, 00:00

Re: Table to store data for aimeos job ?

Post by aimeos » 04 Oct 2020, 11:54

The button is an URL where you can add parameters like here:
https://github.com/aimeos/ai-admin-jqad ... #L249-L253

If you don't need to display a result, remove the madmin_job entry after the job controller was executed or use the message queue instead.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: Table to store data for aimeos job ?

Post by MikaelNazarenko » 04 Oct 2020, 15:35

ok and then the job each time has to find the entry in madmin_job table. But how can I identify it? I can set always same label and identify by label. So if entry found - job will perform the job and remove entry after finished... right ?

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: Table to store data for aimeos job ?

Post by MikaelNazarenko » 04 Oct 2020, 16:07

Ah, please, clarify me what the fields method, parameter, result, status are used for ?

User avatar
aimeos
Administrator
Posts: 8636
Joined: 01 Jan 1970, 00:00

Re: Table to store data for aimeos job ?

Post by aimeos » 05 Oct 2020, 07:45

The method and parameter fields are not used any more and will be removed 2021.

In result a JSON encoded array is stored like

Code: Select all

['file' => 'filename']
to add a file download in the dashboard.

The status value can be 1/0/-1/-2 (enabled/disabled/review/archive).

Use the message queue to create a task and a job controller to process the task. Add a madmin_job entry if you want to show a file download. Use the order export as reference:
- https://github.com/aimeos/ai-admin-jqad ... #L249-L253
- https://github.com/aimeos/ai-admin-jqad ... #L105-L136
- https://github.com/aimeos/ai-controller ... andard.php
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply