Parse.com to Heroku: use background job with heroku and scheduler - ios

I would like to use the first function sayHello in my jobs.js in parse-server-example.
In my jobs.js I have this:
var Parse = require('parse/node');
Parse.initialize('xx', 'xx','xx');
Parse.serverURL = 'xx';
Parse.Cloud.useMasterKey();
function sayHello() {
console.log('Hello');
}
I tried to run it with this terminal line command:
heroku run sayHello -a myAppName
returns:
Running sayHello on myAppName... up, run.6148
bash: sayHello: command not found

You should put the job you want to run in its own file (without a .js extension) outside of a function.
var Parse = require('parse/node');
Parse.initialize('xx', 'xx','xx');
Parse.serverURL = 'xx';
console.log('Hello');
You can then run the following from the command line.
heroku run node nameOfFile --app yourAppName

Related

Run script Ruby on Rails

I have a set of commands that I run in the bin/rails console, for example:
AppConfig.settings.captcha.enable = false
success = user.sign_up
etc ...
Can I make a script like bin/bash to execute all commands at once? (I would like it to be a executable file, since I want to change the input data in it)
You can put the commands into a file (script), add the shebang line (#!/usr/bin/env ruby), make the file executable and run it from the command line like so:
#!/usr/bin/env ruby
# require ... (load the libraries here)
...
AppConfig.settings.captcha.enable = false
success = user.sign_up
#etc ...
# Make executable
chmod u+x my_script.rb
# Run the script
/path/to/my_script.rb

How do I access the exit code of a heroku one-off dyno?

I'm using heroku's platform API + the rendezvous client to execute a command and retrieve it's output + exit code.
def run_command(heroku_client, app_name, command)
dyno = heroku_client.dyno.create(app_name, command: command, attach: true)
rendezvous_url = dyno["attach_url"]
rz = Rendezvous.new({
input:StringIO.new,
output:StringIO.new,
url: rendezvous_url
})
rz.start # Blocks until the command completes
rz.output.rewind
rz.output.readlines.join
end
I can fetch the output just fine, as shown above. I can't find a way to access the exit code though. I tried fetching dyno.info from the API after the process has exited, but I get a 404.
Heroku doesn't support retrieving exit codes from a one-off dyno. One way to achieve this would be to use my_command; echo $? and then parse out the exit code manually. This gem has a plugin that does that.

How to add new custom command to docker API?

I'm trying to add a new customized command to the docker API, along with all the commands found at docker/api/client
I added the following new mycomand.go file to the forked repository:
package client
import (
"fmt"
Cli "github.com/docker/docker/cli"
flag "github.com/docker/docker/pkg/mflag"
)
func (cli *DockerCli) CmdMycomnd(args ...string) error {
cmd := Cli.Subcmd("CmdMycomnd", []string{"CONTAINER"}, Cli.DockerCommands["CmdMycomnd"].Description, true)
cmd.Require(flag.Exact, 1)
cmd.ParseFlags(args, true)
fmt.Println("Hi!")
return nil
}
Also updated docker/cli/common DockerCommands data structure to contain my new command.
Then pushed the commit to the branch in github, following the instructions on docker doc page.
Now, build the docker using make and tried to execute the binary of the 'new' docker which is found in bundles/1.10.0-dev/binary/ by the command:
./docker-1.10.0-dev mycomnd [option]
The Problem: i get the error: docker: 'mycomnd' is not a docker command. Any idea how to get around this?
You need to add a .go file in the directory /api/client along with all the API commands.
The name of the file should be identical to the name of your command.
In that .go file you should include whatever your command does in a function named Cmd[YourCommandName]
Commit and push the changes to your forked github branch.
Make the binary file
Example:
Say you want to add the command ‘talk’, so you do the following:
Add a new source file named talk.go: $ touch talk.go
Add contents of the .go source file.
Update the project on git hub:
$ git add talk.go NOTE: your pwd should be /api/client
$ git commit -s -m "Making a dry run test."
$ git push --set-upstream origin dry-run-test
$ <add your github account name + password>
Now change directory to docker-master directory and make the project
Change directory to /bundles/1.10.0-dev/binary
Execute: ./docker-1-10-dev talk
DONE!
Contents of our new talk command:
package client
import (
"fmt"
Cli "github.com/docker/docker/cli"
flag "github.com/docker/docker/pkg/mflag"
)
func (cli *DockerCli) CmdTalk (args ...string) error {
cmd := Cli.Subcmd("talk", []string{"CONTAINER"}, Cli.DockerCommands["talk"].Description, true)
cmd.Require(flag.Exact, 0)
cmd.ParseFlags(args, true)
fmt.Println("Hi")
return nil
}
Screen Shot

error while executing lua script for redis server

I was following this simple tutorial to try out a simple lua script
http://www.redisgreen.net/blog/2013/03/18/intro-to-lua-for-redis-programmers/
I created a simple hello.lua file with these lines
local msg = "Hello, world!"
return msg
And i tried running simple command
EVAL "$(cat /Users/rsingh/Downloads/hello.lua)" 0
And i am getting this error
(error) ERR Error compiling script (new function): user_script:1: unexpected symbol near '$'
I can't find what is wrong here and i haven't been able to find someone who has come across this.
Any help would be deeply appreciated.
Your problem comes from the fact you are executing this command from an interactive Redis session:
$ redis-cli
127.0.0.1:6379> EVAL "$(cat /path/to/hello.lua)" 0
(error) ERR Error compiling script (new function): user_script:1: unexpected symbol near '$'
Within such a session you cannot use common command-line tools like cat et al. (here cat is used as a convenient way to get the content of your script in-place). In other words: you send "$(cat /path/to/hello.lua)" as a plain string to Redis, which is not Lua code (of course), and Redis complains.
To execute this sample you must stay in the shell:
$ redis-cli EVAL "$(cat /path/to/hello.lua)" 0
"Hello, world!"
If you are coming from windows and trying to run a lua script you should use this format:
redis-cli --eval script.lua
Run this from the folder where your script is located and it will load a multi line file and execute it.
On the off chance that anyone's come to this from Windows instead, I found I had to do a lot of juggling to achieve the same effect. I had to do this:
echo “local msg = 'Hello, world!'; return msg” > hello.lua
for /F "delims=" %i in ('type hello.lua') do #set cmd=%i
redis-cli eval "%cmd%" 0
.. if you want it saved as a file, although you'll have to have all the content on one line. If you don’t just roll the content into a set command
set cmd=“local msg = 'Hello, world!'; return msg”
redis-cli eval "%cmd%" 0

check syntax of ruby/jruby script using jruby -c syntax check (inside ruby code)

I am in a search of some way , using which in ruby code I should be able to create a temp file and then append some ruby code in that, then pass that temp file path to jruby -c to check for any syntax errors.
Currently I am trying the following approach:
script_file = File.new("#{Rails.root}/test.rb", "w+")
script_file.print(content)
script_file.close
command = "#{RUBY_PATH} -c #{Rails.root}/test.rb"
eval(command);
new_script_file.close
When I inspect command var, it is properly showing jruby -c {ruby file path}. But when I execute the above piece of code I am getting the following error:
Completed 500 Internal Server Error in 41ms
SyntaxError ((eval):1: dhunknown regexp options - dh):
Let me know if any one has any idea on this.
Thanks,
Dean
eval evaluates the string as Ruby code, not as a command line invocation:
Since your command is not valid Ruby syntax, you get this exception.
If you want to launch a command in Ruby, you can use %x{} or ``:
output1 = ls
output2 = %x{ls}
Both forms will return the output of the launched command as a String, if you want to process it. If you want this output to be directly displayed in the user terminal, you can use system():
system("ls")

Resources