# Scheduling jobs from a plugin

**URL:** <https://meta.discourse.org/t/scheduling-jobs-from-a-plugin/40238>\
**Category:** Development\
**Created:** [26.Февраль.2016 19:01:09 UTC](https://meta.discourse.org/t/scheduling-jobs-from-a-plugin/40238 "2016-02-26T19:01:09Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![gsch](https://avatars.discourse-cdn.com/v4/letter/g/49beb7/32.png) [@gsch](https://meta.discourse.org/u/gsch)\
**Post date:** [26.Февраль.2016 19:01:09 UTC](https://meta.discourse.org/t/scheduling-jobs-from-a-plugin/40238/1 "2016-02-26T19:01:09Z")

</div>

I am trying to set up a job that runs on a scheduled interval from within a plugin. In my `plugin.rb` I have

```plaintext
after_initialize do
    
    module ::Jobs
        
        module_function
        def count; @count end
        def count= v; @count=v end
        
        Jobs.count =1
    
        class PluginTestJob < ::Jobs::Scheduled
            every 30.seconds
            
            def execute(args)
                puts "I'm working (this job ran #{Jobs.count} times)"
                Jobs.count += 1
            end
        end
    end
  
end

```

I am trying to follow the pattern in `/app/jobs/scheduled`. Is `after_initialize` too late for the job to get scheduled and I have to manually schedule it? Is this on the right track at all?

---

_[View the full topic](https://meta.discourse.org/t/scheduling-jobs-from-a-plugin/40238)._
