Giter Club home page Giter Club logo

Comments (4)

nyeholt avatar nyeholt commented on July 26, 2024

It does, but yes, it should be made clearer that if you do want to use constructor arguments,

a) they must have default parameters, as the JobService will re-create the job class passing through no constructor params
b) you must have logic in your constructor that can determine if it's been constructed by the job service, or by user-land code, and whether the constructor params are to be used.

The kind of logic to use in your constructor could be something like

public function __construct($to = null) {
    if ($to) {
        // we know that we've been called by user code, so
        // do the real initialisation work
    } 
}

Of course, the other alternative is to set properties on the job directly after constructing it from your own code.

from silverstripe-queuedjobs.

nyeholt avatar nyeholt commented on July 26, 2024

Actually, this was mentioned in the wiki, but I've made it a bit clearer, and referenced it from the README file

from silverstripe-queuedjobs.

zarocknz avatar zarocknz commented on July 26, 2024

@nyeholt thanks for somewhat clarifying this, but where exactly can I put the parameters passed in to the constructor of the job in order to persist / make this information available to the running of it across multiple steps?

For example public function __construct($startDate = null, $endDate = null). I want the start and end dates available in the process() function.

Is there something built in to the queued jobs to do this, or will I have to think up my own way of storing the parameters (in DB or file) and then loading them back in the setup() function?

Any guidance you can give on this would be greatly appreciated.

Thanks.

from silverstripe-queuedjobs.

nyeholt avatar nyeholt commented on July 26, 2024

I've made it a little clearer in the wiki page, and copy / pasted below

Job Properties QueuedJobs inherited from the AbstractQueuedJob have a default mechanism for persisting values via the __set and __get mechanism that stores items in the jobData map, which is serialize()d between executions of the job processing. All you need to do from within your job is call $this->myProperty = 'somevalue';, and it will be automatically persisted for you; HOWEVER, on subsequent creation of the job object (ie, in the __constructor()) these properties have not been loaded, so you cannot rely on them at that point.

from silverstripe-queuedjobs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.