XF 2.2 Best practice for special cron-jobs

Robert9

Well-known member
Here is my job:

We have ten different topics with keywords.
Every day we do a cron job for one of the keywords of every topic.
The keywords are more or less finished, there will be less new ones in future.


Solution I
I add ten option_ fields plus one as counter like

name1

color: red, blue, green

name2
size: s, m, l, xl

name3
animals: cats, dogs, birds
...

counter starts with 1


now we do ten times the cron in a day:

1. Fetch counter; => 1
2. fetch the array from name{1}
3. take the first keyword; => red
4. Move the first keyword to the end of the array, save the list, now: blue, green, red
5. save the counter++ while counter < 10 => now 2
6 do the cron-job with "red"

five minutes later

1. Fetch counter; => 2
2. fetch the array from name{2}
3. take the first keyword; => s
4. Move the first keyword to the end of the array, save the list, now: m, l, xl, s
5. save the counter++ while counter < 10 => now 3
6 do the cron-job with "s"

...


Any better idea how to solve this?
 
Have the cron enqueue a job via the job manager. It'll run in the background on page requests, will trigger whenever convenient, and can keep status so you know where to continue.
 
Normally i have a c/p/class calling code in a repository or in ControllerPlugin

To use the functions from my rep, i use something like

Code:
protected function getClassNameRepo()
    {
        return $this->repository('AddonName:ClassName');
    }

$classWithFunctions= getRepo
$myValue= $classWithFunctions->myFunction()

but now i want to call my c/p/class itself from the job_class

call ControllerPlugin
is $this->plugin(

call Repository
is $this->repository(

How to call
Pub/Controller/ClassName?

is there any method to do this like with rep or plugin?


I can move the stuff to a rep, but it is a running system, dont want to touch it and dont want to copy the whole stuff now on a test-server,
also i dont want to double the code into the job_class.

All i need to know is how to use the stuff from my c/p/class in my job/class, please.
To call it with that vars i normally input to a form.
 
You can't call controller methods in other places of your code. If an automated process of your application requires the same code, you'll have to move it to a service or repository.
 
Yes, i tried, but here i am /§%&)"/&§ again.

In my c/p/Index i use

$pageDataPlugin = $this->plugin("Crawler:PageData");
and
$page = $pageDataPlugin->fetchData(...);

so i guess that XF does something only in the c/p/className to have $this->plugin or $this->repository or $this->entity and so on.

but now i need to do that in my cron_class.
How can i just do the same like in a c/p/className in my cronClass, please?

I tried new and use, but i fail.

I just nee something like:
$pageDataPlugin = /AppName/Dir/ClassName[/ICODE]


OR and better:

my cron_class should just call my c/p/index with $params;
then i would be finished with the addon in a minute.
 
Should i curl it to simulate the sending of a form?
Or should i use a job, if a job can use

$pageDataPlugin = $this->plugin("Crawler:PageData");
 
Controller plugins are not available outside the controller context. Services and repositories can be called via the XF class as static methods.
 
Back
Top Bottom