Run cron Tasks at Midnight on Heroku - ruby-on-rails-3

I have created my cron task to run every day at 00:00. However, I don't understand how this works.
I have if Time.now.hour == 0 in my cron.rake but I don't understand if I need to setup the cron:daily addon at midnight?
Anyone care to explain?
Thanks

Heroku's cron:daily addon will only run the cron rake task every day at the time you activate the addon. So the condition in your rake task won't do anything. Just deactivate the cron addon, wait until midnight and then turn it on (probably via command line would be easiest). It's a little annoying that you have to do it this way, but that's what their docs say.
http://devcenter.heroku.com/articles/cron#frequently-asked-questions - Scroll to the bottom.

Related

How to trigger a Spinnaker pipeline by schedule or time?

I have a pipeline setup in Spinnaker where it cuts and deploys a nightly build. I like this to start running at 2am everyday. But I couldn't find any option or documentation on how to do this.
Thanks.
When editing your pipeline, click "Add Trigger" and then choose "CRON" as the trigger type. There is a tooltip on the "CRON Expression" field that gives some help on how to construct the cron expression.
Thanks,
-Matt

How to run Yii controller action In a particular time interval ?

I want to run a Yii controller action in a particular time interval. So I used the Windows 7 task scheduler for performing this. But nothing happens. Is it possible to run the Yii controller action using Windows Task scheduler ?
If so what is the syntax for doing this?
You can implement this with crone jobs. Here are some links which will help you.
1.Implementing cron jobs with Yii
(check the comments there too)
2.Yii and cron jobs
3.Console Applications
4.Yii-Crontab - an extension(Manages system cron jobs. Supports Application console commands)
5.Runactions

Starting multiple upstart instances automatically

We use PHP gearman workers to run various tasks in parallel. Everything works just fine, and I have silly little shell script to spin them up when I want them. Being a programmer (and therefore lazy), I wanted to see if I could spin these up via an upstart script.
I figured out how to use the instance stanza, so I could start them with an instance number:
description "Async insert workers"
author "Mike Grunder"
env SCRIPT_PATH="/path/to/my/script"
instance $N
script
php $SCRIPT_PATH/worker.php
end script
And this works great, to start them like so:
sudo start async-worker N=1
sudo start async-worker N=2
The way I want to use these workers is to spin up some number of them (maybe one per core, etc), and I would like to do this on startup. To be clear, I don't need the upstart script to detect the number of cores. I'm happy to just say "do 8 instances", but that's why I want multiple running. Is there a way for me to use the "start on" clause in an upstart script to do this automatically?
For example, start instance 1, 2, 3, 4? Then have them exit on shutdown properly?
I suppose I could hook this into an init.d script, but I was wondering if upstart can handle something like this, or if anyone has figured out this issue.
Cheers guys!
What you need is a bootstrap task that runs on startup and iterates over all your worker jobs, starting each one.
#/etc/init/async-workers-all.conf
start on runlevel [2345]
task
env NUM_WORKERS=8
script
for i in `seq 1 $NUM_WORKERS`
do
start async-worker N=$i
done
end script
The key is to make this a task, which tells upstart to let the task run to completion before emitting any events for it. See http://upstart.ubuntu.com/cookbook/#task and http://upstart.ubuntu.com/cookbook/#instance

Resque on Heroku not running properly

Im using Resque + RedisToGo for my background jobs. I am having trouble running background tasks on Heroku. Its strange because, the first time I run a background job, it gets executed without any issues. But when I run it again, it doesnt execute. I would have to run "heroku restart', every other time for a background to complete successfully....
For example. If I have the following code in my Resque background action:
module EncodeSong
#queue = :encode_song
def self.perform(media_id, s3_file_url)
puts 'foobar'
media = Media.find(media_id)
puts 'media id is supposed to be here'
puts media.id
puts s3_file_url
end
end
In "heroku console", I do:
Resque.enqueue(EncodeSong, 26, 'http://actual_bucket_name.s3.amazonaws.com/unencoded/users/1/songs/test.mp3')
In "heroku logs", I can see the 4 "puts", when I run the above code for the first time. But running it a second time, only returns 'foobar'. The other "puts" are not displayed.....
I suspect that it is not able to run "media = Media.find(media_id)", the second time around. This is only happening on the production server on Heroku. On our local development machine, we do not experience this problem.... Anyone know what is wrong?
PS. I have tried enabling Heroku logs, but still don't get any useful response. I have followed this tutorial to set up Heroku with Resque
Seems like your job is failing (probably you're right about the 'media = Media.find' line). Look through the resque admin interface. Look for failed jobs, there you'll find the backtrace of each failed job.
Hope this helps.

App launch sequencer

Every morning when I get into work I launch about a dozen apps and whatnot (FF, TB, VSx2-3, Eclipse, SSH, SVN update x2-3). Needles to say this does a good job of warming up my HDD for the day. I rather suspect that it would run a lot faster if they were launched sequentially (not to mention that I wouldn't need to click in 17 different places).
Is there a preexisting product that can kick off a sequence of tasks/apps/etc. where each task is only started after the last app is done hammering the HDD?
It would nerd to be able to kick apps like VS and firefox and also be able to trigger explorer context menu items like SVN update in TortoiseSVN.
Try SlickRun, it's free, I've used it for years, I use it constantly and I'd be lost without it.
Think of it like a configurable Start->Run command, it'll do what you want (you can configure n second pauses between multiple commands), and if you install it you'll use it for a thousand different things before the first week is out.
P.S. I have no stake in SlickRun, I just like it :)
Unfortunately, I don't know of any software that can do this for you automatically.
However, can't you trigger the updates through a console SVN task? If so, can't this be done by creating a batch file? It's low tech, and you might want to add a few pauses between each task, but it should do what you want.
As you mention TortoiseSVN, I'll assume your O/S is windows.
You could launch an Autohotkey script at startup. I don't think it can easily detect HDD activity, but you can at least wait until each window appears with the WinWaitActive command.
If each application has an average time they take to complete, you could simply use Windows' Scheduled Tasks application. Obviously you'll need to be running Windows but Scheduled Tasks can be found in the Control Panel.
Execute "Add Schedules Task", select the program, the frequency and then the specific time.