Class: TQ::App
- Inherits:
-
Object
- Object
- TQ::App
- Defined in:
- lib/tq/app.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#worker ⇒ Object
readonly
Returns the value of attribute worker.
Instance Method Summary collapse
- #application_name ⇒ Object
- #application_version ⇒ Object
- #auth!(secrets_file = nil, store_file = nil) ⇒ Object
- #env(_) ⇒ Object
-
#initialize(id, worker, options = {}) ⇒ App
constructor
A new instance of App.
- #log(_) ⇒ Object
- #logger(_) ⇒ Object
- #options(_) ⇒ Object
- #project(_) ⇒ Object
- #run!(secrets_file = nil, store_file = nil) ⇒ Object
- #service_auth!(issuer, p12_file) ⇒ Object
- #stderr(_) ⇒ Object
- #stdin(_) ⇒ Object
- #stdout(_) ⇒ Object
Constructor Details
#initialize(id, worker, options = {}) ⇒ App
Returns a new instance of App.
26 27 28 29 |
# File 'lib/tq/app.rb', line 26 def initialize(id, worker, ={}) @id = id; @worker = worker @options = DEFAULT_OPTIONS.merge() end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
25 26 27 |
# File 'lib/tq/app.rb', line 25 def id @id end |
#worker ⇒ Object (readonly)
Returns the value of attribute worker.
25 26 27 |
# File 'lib/tq/app.rb', line 25 def worker @worker end |
Instance Method Details
#application_name ⇒ Object
107 108 109 |
# File 'lib/tq/app.rb', line 107 def application_name @id.split('/')[0] end |
#application_version ⇒ Object
111 112 113 |
# File 'lib/tq/app.rb', line 111 def application_version @id.split('/')[1] || '0.0.0' end |
#auth!(secrets_file = nil, store_file = nil) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/tq/app.rb', line 87 def auth!(secrets_file=nil, store_file=nil) if store_file.nil? || (cred_store = credentials_store(store_file))..nil? client_secrets = Google::APIClient::ClientSecrets.load(secrets_file) flow = Google::APIClient::InstalledAppFlow.new( :client_id => client_secrets.client_id, :client_secret => client_secrets.client_secret, :scope => TASKQUEUE_API_SCOPES ) client. = store_file.nil? ? flow. : flow.(cred_store) else client. = cred_store. end api = client.discovered_api(TASKQUEUE_API, TASKQUEUE_API_VERSION) return client, api end |
#env(_) ⇒ Object
47 48 49 |
# File 'lib/tq/app.rb', line 47 def env(_) ({'env' => @options['env'].merge(_)}) end |
#log(_) ⇒ Object
39 40 41 |
# File 'lib/tq/app.rb', line 39 def log(_) ({'log' => @options['log'].merge(_)}) end |
#logger(_) ⇒ Object
43 44 45 |
# File 'lib/tq/app.rb', line 43 def logger(_) ({'logger' => _}) end |
#options(_) ⇒ Object
31 32 33 |
# File 'lib/tq/app.rb', line 31 def (_) App.new @id, @worker, @options.merge(_) end |
#project(_) ⇒ Object
35 36 37 |
# File 'lib/tq/app.rb', line 35 def project(_) ({'project' => _}) end |
#run!(secrets_file = nil, store_file = nil) ⇒ Object
66 67 68 69 |
# File 'lib/tq/app.rb', line 66 def run!(secrets_file=nil, store_file=nil) setup_logger! _run *(_queues( TQ::Queue.new( *(auth!(secrets_file, store_file)) ).project(@options['project']) ) ) end |
#service_auth!(issuer, p12_file) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/tq/app.rb', line 72 def service_auth!(issuer, p12_file) key = Google::APIClient::KeyUtils.load_from_pkcs12(p12_file, 'notasecret') client. = Signet::OAuth2::Client.new( :token_credential_uri => 'https://accounts.google.com/o/oauth2/token', :audience => 'https://accounts.google.com/o/oauth2/token', :scope => TASKQUEUE_API_SCOPES, :issuer => issuer, :signing_key => key) client..fetch_access_token! api = client.discovered_api(TASKQUEUE_API, TASKQUEUE_API_VERSION) return client, api end |
#stderr(_) ⇒ Object
61 62 63 64 |
# File 'lib/tq/app.rb', line 61 def stderr(_) return stderr({'name' => _}) if String === _ ({'stderr' => _}) end |
#stdin(_) ⇒ Object
51 52 53 54 |
# File 'lib/tq/app.rb', line 51 def stdin(_) return stdin({'name' => _}) if String === _ ({'stdin' => _}) end |
#stdout(_) ⇒ Object
56 57 58 59 |
# File 'lib/tq/app.rb', line 56 def stdout(_) return stdout({'name' => _}) if String === _ ({'stdout' => _}) end |